package org.ezplatform.office.approve.web.rest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.ezplatform.cloud.api.component.attachment.AttachmentUtilsService;
import org.ezplatform.cloud.api.model.formmgr.FormApiService;
import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.cloud.common.log.LogService;
import org.ezplatform.component.permission.service.CmpPermissionService;
import org.ezplatform.component.permission.service.CmpSystemDataService;
import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.pagination.PropertyFilter;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.integ.websocket.annotation.WebsocketCode;
import org.ezplatform.integ.websocket.constant.WebsocketConstant;
import org.ezplatform.integ.websocket.util.WebsocketUtils;
import org.ezplatform.office.approve.client.ApproveApiClient;
import org.ezplatform.office.approve.constant.ApproveConstants;
import org.ezplatform.office.approve.constant.WebsocketApproveConstant;
import org.ezplatform.office.approve.dto.UrgeMsgDto;
import org.ezplatform.office.approve.entity.BpmProcessDealtips;
import org.ezplatform.office.approve.service.*;
import org.ezplatform.office.approve.utils.ApproveSecUtils;
import org.ezplatform.office.approve.utils.ApproveValidateUtils;
import org.ezplatform.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.annotation.Resource;
import org.ezplatform.sdk.AccessToken;
import org.ezplatform.sdk.Client;
import org.springframework.jdbc.core.JdbcTemplate;

@RestController
@RequestMapping("/api/w/approve/flow/pending")
@Api(value = "审批办理", description = "审批应用办理相关api")
public class PendingTaskWebApiController {
    public static final Logger LOG = LoggerFactory.getLogger(PendingTaskWebApiController.class);
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private PendingTaskService pendingTaskService;

    @Autowired
    private UserApiService userApiService;

    @Autowired
    private LogService logService;

    @Autowired
    private BpmFollowService bpmFollowService;

    @Autowired
    private BpmProcessExtendService bpmProcessExtendService;

    @Autowired
    private BpmProcessDealtipsService bpmProcessDealtipsService;

    @Autowired
    private AttachmentUtilsService attachmentUtilsService;

    @Autowired
    private BpmProcessTextlockService bpmProcessTextlockService;

    @Autowired
    private CmpPermissionService cmpPermissionService;

    @Autowired
    private ApproveApiClient approveApiClient;

    @Autowired
    private CmpSystemDataService cmpSystemDataService;

    @Autowired
    private BpmProcessFormofdService bpmProcessFormofdService;

    @Autowired
    private BpmProcessHiFormofdService bpmProcessHiFormofdService;

    @Autowired
    private ApproveCacheService approveCacheService;

    @Autowired
    private ApproveTaskService approveTaskService;

    @Autowired
    @Lazy
    private ApproveSendMessageApiService approveSendMessageApiService;

    @Autowired
    private PendingTaskExecutorService pendingTaskExecutorService;

    @Autowired
    private FormApiService formApiService;

    @Autowired
    private ApproveTransformService approveTransformService;

    @ApiOperation(value = "获取所有流程列表数据", notes = "获取所有流程列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchTreeData", value = "搜索值", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "类型(0待办，1待阅，2已办，3已阅，4我的，5草稿箱,6关注流程,7流程转交，8下属待办)", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "流程编码", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getNewAllFlow", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult getNewAllFlow(HttpServletRequest request) {
        String res = this.approveTaskService.getNewAllFlow(request);
        if(StringUtils.isNotBlank(res)){
            return OperationResult.buildSuccessResult("获取成功",res);
        }else{
            return OperationResult.buildFailureResult("获取所有流程列表数据失败");
        }
    }

    @ApiOperation(value = "待办列表", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "start", value = "页数", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "限制数量", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "流程编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "category", value = "流程分类", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startUserName", value = "流程发起用户名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间-开始", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间-结束", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startGroupName", value = "发起组织名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTimeBegin", value = "开始时间-开始", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTimeEnd", value = "开始时间-结束", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "流程状态  11-退回   12-转交", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "moduleCodelist", value = "模块code列表", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "unified", value = "查询字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "buttonGroup", value = "按钮组", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sourceType", value = "来源类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processName", value = "流程名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderby", value = "", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "order", value = "", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isNotOwner", value = "", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isDeal", value = "状态（1暂不处理，0恢复暂不处理", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/pendingTaskList", method = RequestMethod.GET)
    @ResponseBody
    public Page pendingTaskList(HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }

        return this.pendingTaskService.pendingTaskList(request,user.getUserId(), orgId, user.getCorpId(), user.getJwtToken());
    }
    
    @ApiOperation(value = "打开办理或新增页面", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "showFields", value = "显示字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editFields", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "hiddenFields", value = "隐藏字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "mustFields", value = "必填字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "mobileFields", value = "移动端字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignFields", value = "不赋值字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "subtable", value = "子表", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型1-html 4-矩阵", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "category", value = "流程分类", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isPrint", value = "是否打印", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentName", value = "批示意见名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "owntype", value = "来源类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isReplyComment", value = "批示意见是否可回复", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "enableCommentArea", value = "批示意见是否显示", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isToLeader", value = "是否呈领导", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processKey", value = "流程key", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "flowLogType", value = "流程记录是否表单显示：0-页签，1-表单", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowQuick", value = "快捷批示显示：0-否，1-是", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "quickContent", value = "快捷批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "inscriptionShow", value = "批示意见落款显示", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgShowType", value = "批示意见落款 组织类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentPlace", value = "批示意见框位置", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentUploadFile", value = "批示意见上传附件", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentCanEdit", value = "批示意见是否可编辑", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "nowTaskDefKey", value = "当前任务code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageHandSignature", value = "网页签批（1pc端，2移动端）", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isSubTblImp", value = "是否启用子表导入  1-是  0-否", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isSubTblExp", value = "是否启用子表导出  1-是  0-否", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentAttitude", value = "是否启用子表导入  1-是  0-否", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/viewFlowInfo", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult viewFlowInfo(HttpServletRequest request) {
        LOG.debug("请求了viewFlowInfo接口");
        Map<String, String> res = this.pendingTaskService.viewFlowInfo(request);
        String data = StringUtils.null2String(res.get("data"));
        String errorMsg = StringUtils.null2String(res.get("errorMsg"));
        if(StringUtils.isNotBlank(data)){
            LOG.error("### viewFlowInfo data:"+data);
            return pendingTaskService.stringToOperation(data);
        }else{
            if(StringUtils.isBlank(errorMsg)){
                errorMsg = "获取表单失败";
            }
            return OperationResult.buildFailureResult(errorMsg);
        }
    }

    @ApiOperation(value = "领导审批(呈领导)", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "leaderId", value = "领导id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "leaderName", value = "领导姓名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formData", value = "表单数据", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "可编辑", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealActionName", value = "操作按钮名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/leaderProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult leaderProcess(HttpServletRequest request) {
        Map<String, String> res = this.pendingTaskService.leaderProcess(request);
        String data = StringUtils.null2String(res.get("data"));
        String errorMsg = StringUtils.null2String(res.get("errorMsg"));
        if(StringUtils.isNotBlank(data)){
            return pendingTaskService.stringToOperation(data);
        }else{
            if(StringUtils.isBlank(errorMsg)){
                errorMsg = "领导审批失败";
            }
            return OperationResult.buildFailureResult(errorMsg);
        }
    }

    @ApiOperation(value = "获取流程办理信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "recycleQuery", value = "回收站查看 1是", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getProcessInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getProcessInfo(String taskId, String processInstanceId, String menuType, String module,String recycleQuery ,HttpServletRequest request) {
        LOG.debug("### 请求了getProcessInfo接口");
        LOG.debug("### getProcessInfo接口中的processInstanceId："+processInstanceId);

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if( ( !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode))){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> res = this.pendingTaskService.getProcessInfo(taskId, processInstanceId, menuType, module,recycleQuery,user.getUserId(), user.getCnName(), user.getCorpId(),user.getJwtToken());
        String data = StringUtils.null2String(res.get("data"));
        String errorMsg = StringUtils.null2String(res.get("errorMsg"));
        if(StringUtils.isNotBlank(data)){
            return pendingTaskService.stringToOperation(data);
        }else{
            if(StringUtils.isBlank(errorMsg)){
                errorMsg = "获取流程办理信息失败";
            }
            return OperationResult.buildFailureResult(errorMsg);
        }
    }

    @ApiOperation(value = "获取待办任务信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "lock", value = "流程锁", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "replaceUserId", value = "代签用户id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUndoTaskInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUndoTaskInfo(String taskId, String processInstanceId,
                                           String lock, String replaceUserId, String menuType,HttpServletRequest request) {

        Map<String, String> res = this.pendingTaskService.getUndoTaskInfo(taskId, processInstanceId, lock, replaceUserId, menuType, request);
        String data = StringUtils.null2String(res.get("data"));
        String errorMsg = StringUtils.null2String(res.get("errorMsg"));
        if(StringUtils.isNotBlank(data)){
            Map obj = JsonUtils.readValue(data);
            Map content = obj.get("content")==null?null:(Map)obj.get("content");
            if(content!=null){
                return OperationResult.buildFailureResult("获取失败",content);
            }else{
                return pendingTaskService.stringToOperation(data);
            }
        }else{
            if(StringUtils.isBlank(errorMsg)){
                errorMsg = "获取待办任务信息失败";
            }
            return OperationResult.buildFailureResult(errorMsg);
        }
    }

    @ApiOperation(value = "代录签收任务", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "replaceUserId", value = "代签用户id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/replaceTask", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult replaceTask(HttpServletRequest request, String taskId, String replaceUserId) throws Exception {
        Map<String, String> res = this.pendingTaskService.replaceTask(request, taskId, replaceUserId);
        LOG.debug("res:"+JSON.toJSONString(res));
        String data = StringUtils.null2String(res.get("data"));
        String errorMsg = StringUtils.null2String(res.get("errorMsg"));
        String[] split = replaceUserId.split(",");
        ArrayList<String> receiver=new ArrayList<>();
        WebUser user = WebUtils.getCurrentUser();
        receiver.add(user.getUserId());
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i]);
        }
        if(StringUtils.isNotBlank(data)){
                Map map=JsonUtils.readValue(data);
                if(StringUtils.equals("success", map.get("type")+"")){

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                    WebsocketApproveConstant.refrashDealData(receiver);

                    return OperationResult.buildSuccessResult(map.get("data"));
                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));

        }else{
            if(StringUtils.isBlank(errorMsg)){
                errorMsg = "代录签收任务失败";
            }
            return OperationResult.buildFailureResult(errorMsg);
        }
    }

    @ApiOperation(value = "保存表单数据", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formData", value = "表单数据", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "编辑字段", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/saveForm", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult saveForm(String formData, String editType, String allEditIds, String dataId, String formType) {
        Map<String, String> params = new HashMap<String, String>();
        WebUser user = WebUtils.getCurrentUser();
        params.put("userId", user.getUserId());
        params.put("formData", formData);
        params.put("editType", editType);
        params.put("allEditIds", allEditIds);
        params.put("dataId", dataId);
        params.put("formType", formType);
        String json = approveApiClient.saveFormData( params,formData,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程发送 包括发起和办理", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formData", value = "表单数据", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "编辑字段", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式  0-单人 1-会签 2-串签 3-抢占", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealActionName", value = "操作按钮名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "流程code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "auditorUserIds", value = "审批用户id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "selectedActivity", value = "所选流程节点", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgent", value = "流程催办", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "lock", value = "流程锁", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "secretLevel", value = "密级", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "activityNodeNow", value = "1-当前活动  2-后继活动", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentSource", value = "批示意见来源", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "titleSetValue", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgentField", value = "紧急程度字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "callProInsId", value = "调用流程实例id  多个英文逗号分割", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "callMainProInsId", value = "调用过程主流程的实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "callMainDoneTaskId", value = "调用过程主流程的任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isChangeTitle", value = "是否更改流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealRemarkText", value = "办理提示", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/sendFlow", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult sendFlow(String formData, String editType, String allEditIds, String dataId, String taskId,
                                    String module, String formType, String processInstanceId, String menuType, String participantMode,
                                    String dealActionName, String code, String auditorUserIds, String selectedActivity, String urgent,
                                    String permissionCode, String comment, String commentType, String lock, HttpServletRequest request) {

        LOG.debug("sendFlow   流程发送或办理...");
        String callMainActivityId = StringUtils.null2String(request.getParameter("callMainActivityId"));
        String dealCallMainProcess = StringUtils.null2String(request.getParameter("dealCallMainProcess"));
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        List<String> list = new ArrayList<>();
        list.add("processInstanceId"+processInstanceId);
        list.add("id"+taskId);//参数加密时用的是id  故此处不是taskId
        if(!(StringUtils.isNotBlank(dealCallMainProcess) || StringUtils.isNotBlank(callMainActivityId)) && !ApproveSecUtils.verifyData(list,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String msgType = request.getParameter("msgType");
        String commentId = request.getParameter("commentId");
        String secretLevel = request.getParameter("secretLevel");
        String activityNodeNow = request.getParameter("activityNodeNow");
        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentSource = StringUtils.null2String(request.getParameter("commentSource"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String titleSetValue = StringUtils.null2String(request.getParameter("titleSetValue"));
        //紧急程度
        String urgentField = StringUtils.null2String(request.getParameter("urgentField"));
        String callProInsId = StringUtils.null2String(request.getParameter("callProInsId"));
        String callMainProInsId = StringUtils.null2String(request.getParameter("callMainProInsId"));
        String callMainDoneTaskId = StringUtils.null2String(request.getParameter("callMainDoneTaskId"));
        String isChangeTitle = StringUtils.null2String(request.getParameter("isChangeTitle"));
        //办理提示
        String dealRemarkText = StringUtils.null2String(request.getParameter("dealRemarkText"));

        //直接通过任务id 传给引擎 流程记录使用
        String nextTaskId = StringUtils.null2String(request.getParameter("nextTaskId"));
        // 发送上级领导
        String isSendToLeader = StringUtils.null2String(request.getParameter("isSendToLeader"));

        String sapJson = StringUtils.null2String(request.getParameter("sapJson"));
        String endSapJson = StringUtils.null2String(request.getParameter("endSapJson"));
        String batchSubProcess = StringUtils.null2String(request.getParameter("batchSubProcess"));

        String permissionCodes = module + ":" + permissionCode + ":tg";
        if (StringUtils.equals("start", menuType)) {
            permissionCodes = module + ":" + permissionCode + ":tj";
        } else if (StringUtils.equals("draft", menuType)) {
            permissionCodes = module + ":" + permissionCode + ":tj";
        }
        if (StringUtils.equals("readd", editType)) {
            editType = "add";
            dataId = "";
        }
        boolean verifyRes = this.pendingTaskService.verifyDealUserInfo(selectedActivity, taskId);
        if(!verifyRes){
            LOG.error("sendFlow   待办用户校验失败");
            return OperationResult.buildFailureResult("待办用户校验失败");
        }

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();
        //如是涉密环境 校验办理人密级是否符合文件密级
        if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
            int secretLevelnum = 0;
            try{
                secretLevelnum = Integer.parseInt(secretLevel);
            }catch(Exception e){
                LOG.error("sendFlow   secretLevel 不是数字",e);
                return OperationResult.buildFailureResult("密级参数异常，请重新选择");
            }
            String userNames = this.pendingTaskService.getUserNotInSecretLevel(selectedActivity, secretLevelnum, corpId, token);
            if (StringUtils.isNotBlank(userNames)) {
                LOG.error("sendFlow   "+userNames + "低于文件密级，请重新选择");
                return OperationResult.buildFailureResult(userNames + "低于文件密级，请重新选择");
            }
        }

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("userId", userId);
        bodyParams.put("batchSubProcess", batchSubProcess);
        Map<String, Object> paramMap = null;
        if (StringUtils.isNotBlank(formData)) {
            try {
                paramMap = JsonUtils.readValue(formData);
                bodyParams.put("formData", paramMap);
            } catch (Exception e1) {
                LOG.error("sendFlow    处理formdata数据异常：", e1);
                return OperationResult.buildFailureResult("处理formdata数据异常");
            }
        }

        bodyParams.put("editType", editType);
        bodyParams.put("allEditIds", allEditIds);
        bodyParams.put("dataId", dataId);
        boolean logEnable = logService.checkOptLog(user.getCorpId(), permissionCodes, user.getJwtToken());
        Map<String, String> rmap = new HashMap<String, String>();
        rmap.put("logEnable", logEnable ? "1" : "0");
        bodyParams.put("extParam", JsonUtils.writeValueAsString(rmap));
        if (null != comment) {
            bodyParams.put("comment", comment);
            bodyParams.put("commentType", commentType);
            bodyParams.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                bodyParams.put("commentId", commentId);
            }
        }
        bodyParams.put("commentSource", commentSource);
        bodyParams.put("lock", lock);
        bodyParams.put("formType", formType);
        bodyParams.put("dealActionName", dealActionName);
        // 流程审批人
        if (StringUtils.isNotBlank(auditorUserIds)) {
            bodyParams.put("auditorUserIds", auditorUserIds);
        }
        if (StringUtils.isNotBlank(selectedActivity)) {
            bodyParams.put("selectedActivity", selectedActivity);
        }

        if (StringUtils.isNotBlank(urgent) && !"null".equals(urgent) && !"undefined".equals(urgent)) {
            bodyParams.put("urgency", urgent);
        }

        if(StringUtils.isNotBlank(msgType) && !"null".equals(msgType) && !"undefined".equals(msgType)){
            bodyParams.put("msgType", msgType);
        }else if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
            bodyParams.put("secretLevel", secretLevel);
        }
        bodyParams.put("userName", user.getCnName());
        bodyParams.put("activityNodeNow", activityNodeNow);
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        bodyParams.put("titleSetValue", titleSetValue);
        //if (StringUtils.isNotBlank(urgentField)) {
            bodyParams.put("urgentField", urgentField);
        //}
        if (StringUtils.isNotBlank(dealRemarkText)) {
            bodyParams.put("dealRemarkText", dealRemarkText);
        }
        if (StringUtils.isNotBlank(callMainActivityId)) {
            bodyParams.put("callMainActivityId", callMainActivityId);
        }
        if (StringUtils.isNotBlank(callMainProInsId)) {
            bodyParams.put("callMainProInsId", callMainProInsId);
        }
        if (StringUtils.isNotBlank(callProInsId)) {
            bodyParams.put("callProInsId", callProInsId);
        }
        if (StringUtils.isNotBlank(callMainDoneTaskId)) {
            bodyParams.put("callMainDoneTaskId", callMainDoneTaskId);
        }
        if (StringUtils.isNotBlank(isChangeTitle)) {
            bodyParams.put("isChangeTitle", isChangeTitle);
        }

        bodyParams.put("sapJson",sapJson);
        bodyParams.put("endSapJson",endSapJson);

        bodyParams.put("nextTaskId",nextTaskId);
        bodyParams.put("isSendToLeader",isSendToLeader);

        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        try {
            LOG.debug("sendFlow  params:"+JSON.toJSONString(params));
            String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
            LOG.debug("sendFlow  bodyDataParams:"+bodyDataParams);
            String json = approveApiClient.completeTask( params,bodyDataParams,user.getJwtToken());
            LOG.debug("sendFlow  json:"+json);
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
                String modiInfo = "";
                boolean isStart=false;
                if (null != dataMap && null != dataMap.get("modiInfo")) {
                    modiInfo = dataMap.get("modiInfo") + "";
                }
                if (null != dataMap && null != dataMap.get("dataId")) {
                    dataId = dataMap.get("dataId") + "";
                }
                if (StringUtils.isNotBlank(dataId)) {
                    map.put("dataId", dataId);
                } else {
                    if (StringUtils.isBlank(dataId)) {
                        dataId = pendingTaskService.getBusiIdByProInsId(processInstanceId);
                    }
                    map.put("dataId", dataId);
                }
                if (StringUtils.equals("start", menuType) || StringUtils.equals("draft", menuType)){
                    isStart=true;
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);

                //统一待办改为已办
                LOG.error("------takeMsgDoneSleep-----start-----"+taskId+"----isStart---"+isStart);
                if(!isStart){
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
                }

                //更新日志信息
                if (StringUtils.isNotBlank(modiInfo)) {
                    pendingTaskExecutorService.updateProcessLogExecutor(processInstanceId, taskId, user.getCorpId(), modiInfo,"0");
                }
                if (StringUtils.isNotBlank(selectedActivity)) {
                    List<Map<String, String>> lm = JsonUtils.readListValue(selectedActivity);
                    String isEnd = "0";
                    for (Map<String, String> m1 : lm) {
                        if (StringUtils.equals("end_node", m1.get("id"))) {
                            isEnd = "1";
                        }
                    }

                    //更新流程表单关系
                    if (StringUtils.isNotBlank(formData)){
                        Map<String, Object> formMap = JsonUtils.readValue(formData);
                        String formId = formMap.get("formId") + "";
                        boolean isAdd = false;
                        if (StringUtils.equals("start", menuType) || StringUtils.equals("draft", menuType)) {
                            isAdd = true;
                        }
                        pendingTaskService.insertUpdateFormSql(isEnd, isAdd, formId, dataId, processInstanceId);
                    }
                }

                //插入扩展信息
                if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
                    bpmProcessExtendService.updateProcessExtend(processInstanceId, secretLevel);
                }

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                /** 清理办理人信息的缓存 **/
                this.pendingTaskService.delApproveDealUserCache(selectedActivity,taskId);
                /** 清理办理人正文锁信息 **/
                bpmProcessTextlockService.delTextlock(userId,processInstanceId);
                //记录模块 日志
                if (logEnable) {
                    logService.saveModuleLog(permissionCodes, titleSetValue, modiInfo);
                }

            } else {
                if (logEnable) {
                    String title = pendingTaskService.getTitleByProInsId(processInstanceId);
                    logService.saveModuleLog(permissionCodes, title, "", UuidUtils.UUID());
                }
            }
            LOG.debug("sendFlow    map："+JSON.toJSONString(map));

            /*ArrayList<String> receiver = new ArrayList<>();
            receiver.add(user.getUserId());
            if (StringUtils.isNotBlank(selectedActivity)) {
                List<Map<String, String>> lm = JsonUtils.readListValue(selectedActivity);
                if(lm!=null && lm.size()>0){
                    for(Map<String, String> p:lm){
                        String participants = StringUtils.null2String(p.get("participants"));
                        receiver.addAll(Arrays.asList(participants.split(",")));
                    }
                }
            }*/
            if(StringUtils.isNotBlank(JSON.toJSONString(map))){
                Map map1=JsonUtils.readValue(JSON.toJSONString(map));
                if(StringUtils.equals("success", map1.get("type")+"")){

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                  //  WebsocketApproveConstant.refrashDealData(receiver);


                    return OperationResult.buildSuccessResult(map1.get("data"));
                }
                return OperationResult.buildFailureResult(map1.get("message")+"", map1.get("data"));
            }
            return OperationResult.buildFailureResult("参数不能为空");
        } catch (Exception e) {
            if (logEnable) {
                String title = pendingTaskService.getTitleByProInsId(processInstanceId);
                logService.saveModuleLog(permissionCodes, title, "", UuidUtils.UUID());
            }
            LOG.error("sendflow    提交失败", e);
            return OperationResult.buildFailureResult("提交失败");
        }
    }

    @ApiOperation(value = "流程转交", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式  0-单人 1-会签 2-串签 3-抢占", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignId", value = "转交人id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assigneeNames", value = "转交人姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "automaticReturn", value = "是否自动返回 1-是", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formData", value = "表单数据", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "修改的表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "titleSetValue", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgentField", value = "紧急程度字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "secretLevel", value = "密级", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/transferFlow", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult transferFlow(String taskId, String assignId, String module, String comment, String commentType,
                                        String formType, String assigneeNames, String formId, String dataId, String processInstanceId,
                                        String participantMode, String permissionCode, HttpServletRequest request) {
        LOG.debug("transferFlow    流程转交....");
        LOG.debug("taskId:"+taskId);


        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String automaticReturn = request.getParameter("automaticReturn");
        String title = request.getParameter("processTitle");
        String commentId = request.getParameter("commentId");
        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String formData = StringUtils.null2String(request.getParameter("formData"));
        String allEditIds = StringUtils.null2String(request.getParameter("allEditIds"));
        String editType = StringUtils.null2String(request.getParameter("editType"));
        String titleSetValue = StringUtils.null2String(request.getParameter("titleSetValue"));
        String urgentField = StringUtils.null2String(request.getParameter("urgentField"));
        String secretLevel = StringUtils.null2String(request.getParameter("secretLevel"));
        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        Map<String, String> params = new HashMap<String, String>();
        // 流程审批人
        if (StringUtils.isNotBlank(assignId)) {
            params.put("assignees", assignId);
            params.put("assigneeNames", assigneeNames);
        }
        params.put("userId", userId);
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        if (comment != null) {
            params.put("comment", comment);
            params.put("commentType", commentType);
            params.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                params.put("commentId", commentId);
            }
        }

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("formData", JsonUtils.readValue(formData));
        bodyParams.put("allEditIds", allEditIds);
        bodyParams.put("editType", editType);
        bodyParams.put("titleSetValue", titleSetValue);
        bodyParams.put("urgentField", urgentField);
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
            bodyParams.put("secretLevel", secretLevel);
        }
        bodyParams.put("dataId", dataId);
        bodyParams.put("formId", formId);
        bodyParams.put("formType", formType);
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        bodyParams.put("automaticReturn", automaticReturn);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        permissionCode = module + ":" + permissionCode + ":zj";

        LOG.debug("params:"+JsonUtils.writeValueAsString(params));
        LOG.debug("bodyParams:"+JsonUtils.writeValueAsString(bodyParams));

        String json = approveApiClient.transferTask_mutil( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());

        LOG.debug("json:"+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, titleSetValue, null);
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId  , ms,user.getUserId(),user.getCorpId(),user.getJwtToken());

                Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
                String modiInfo = "";
                if (null != dataMap && null != dataMap.get("modiInfo")) {
                    modiInfo = dataMap.get("modiInfo") + "";
                }
                if (StringUtils.isNotBlank(modiInfo)) {
                    pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), modiInfo,
                            "0", pendingTaskService.getDoingTaskIds(processInstanceId));
                }

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);

                /** 清理办理人正文锁信息 **/
                bpmProcessTextlockService.delTextlock(userId,processInstanceId);
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程转交失败", e);
            return OperationResult.buildFailureResult("流程转交失败");
        }
        ArrayList<String> receiver=new ArrayList<>();
        receiver.add(assignId);
        receiver.add(user.getUserId());
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
              //  WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    //20240726gaoyw秘书自定义转交获取领导待办列表-s
    @ApiOperation(value = "流程转交", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式  0-单人 1-会签 2-串签 3-抢占", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignId", value = "转交人id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assigneeNames", value = "转交人姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "automaticReturn", value = "是否自动返回 1-是", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formData", value = "表单数据", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "修改的表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "titleSetValue", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgentField", value = "紧急程度字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "secretLevel", value = "密级", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/myTransferFlow", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult myTransferFlow(String taskId, String assignId, String module, String comment, String commentType,
                                          String formType, String assigneeNames, String formId, String dataId, String processInstanceId,
                                          String participantMode, String permissionCode, HttpServletRequest request) throws Exception {
        LOG.debug("myTransferFlowtransferFlow    流程转交....");
        LOG.debug("myTransferFlowtaskId:"+taskId);


        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String automaticReturn = request.getParameter("automaticReturn");
        String title = request.getParameter("processTitle");
        String commentId = request.getParameter("commentId");
        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String formData = StringUtils.null2String(request.getParameter("formData"));
        String allEditIds = StringUtils.null2String(request.getParameter("allEditIds"));
        String editType = StringUtils.null2String(request.getParameter("editType"));
        String titleSetValue = StringUtils.null2String(request.getParameter("titleSetValue"));
        String urgentField = StringUtils.null2String(request.getParameter("urgentField"));
        String secretLevel = StringUtils.null2String(request.getParameter("secretLevel"));
        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String leaderId = myTransferFlowLeaderId(userId);
        String leaderOrgId = myTransferFlowLeaderOrgId(userId);
        String leaderLoginName = myTransferFlowLeaderLoginName(userId);
        String leaderName = myTransferFlowLeaderLoginName(userId);
        String token = ssoAuth2(leaderLoginName);

        OperationResult operationResult = myClaimTask(taskId, leaderId, "1", token);//先进性签收,然后才可以进行转办
        LOG.debug("myTransferFlowparams:"+leaderId+"|"+leaderOrgId+"|"+leaderLoginName+"|"+operationResult);



        Map<String, String> params = new HashMap<String, String>();
        // 流程审批人
        if (StringUtils.isNotBlank(leaderId)) {
            params.put("assignees", assignId);
            params.put("assigneeNames", assigneeNames);
        }
        params.put("userId", leaderId);
        params.put("corpId", "0");
        String orgId = leaderOrgId;
//        if (StringUtils.isBlank(orgId)) {
//            orgId = user.getOrgId();
//        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        if (comment != null) {
            params.put("comment", comment);
            params.put("commentType", commentType);
            params.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                params.put("commentId", commentId);
            }
        }

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("formData", JsonUtils.readValue(formData));
        bodyParams.put("allEditIds", allEditIds);
        bodyParams.put("editType", editType);
        bodyParams.put("titleSetValue", titleSetValue);
        bodyParams.put("urgentField", urgentField);
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
            bodyParams.put("secretLevel", secretLevel);
        }
        bodyParams.put("dataId", dataId);
        bodyParams.put("formId", formId);
        bodyParams.put("formType", formType);
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        bodyParams.put("automaticReturn", automaticReturn);
        permissionCode = module + ":" + permissionCode + ":zj";


        LOG.debug("myTransferFlowparams:"+JsonUtils.writeValueAsString(params));
        LOG.debug("myTransferFlowbodyParams:"+JsonUtils.writeValueAsString(bodyParams));

        String json = approveApiClient.transferTask_mutil( params,JsonUtils.writeValueAsString(bodyParams),token);

        LOG.debug("json:"+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog("0", permissionCode, token)) {
                    logService.saveModuleLog(permissionCode, titleSetValue, null);
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId  , ms,leaderId,"0",token);

                Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
                String modiInfo = "";
                if (null != dataMap && null != dataMap.get("modiInfo")) {
                    modiInfo = dataMap.get("modiInfo") + "";
                }
                if (StringUtils.isNotBlank(modiInfo)) {
                    pendingTaskService.updateProcessLog(processInstanceId, taskId, "0", modiInfo,
                            "0", pendingTaskService.getDoingTaskIds(processInstanceId));
                }
                //修改秘书转交得时候业务操作，从转办改成秘书转办-s
                String sql="update bpm_process_log set dealactionname='秘书转交' where process_instance_id='"+processInstanceId+"' and taskid='"+taskId+"' and dealaction='transfer' ";
                jdbcTemplate.update(sql);
                //修改秘书转交得时候业务操作，从转办改成秘书转办-s

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);

                /** 清理办理人正文锁信息 **/
                bpmProcessTextlockService.delTextlock(leaderId,processInstanceId);
            } else {
                if (logService.checkOptLog("0", permissionCode, token)) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog("0", permissionCode, token)) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程转交失败", e);
            return OperationResult.buildFailureResult("流程转交失败");
        }
        ArrayList<String> receiver=new ArrayList<>();
        receiver.add(assignId);
        receiver.add(leaderId);
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }
    //根据秘书得id获取领导得id
    public String myTransferFlowLeaderId(String userId) {
        String sql = "SELECT scopevalue leader_id ,name leader_name,su.login_name FROM ldgx_scope LEFT  JOIN sys_user su ON su.id=scopevalue WHERE \"fielddatavalue\"=(SELECT f1 FROM ldgx WHERE f2 in(SELECT fielddatavalue FROM ldgx_scope WHERE \"scopevalue\"=?)) ";
        List<Map<String, Object>> rlist=jdbcTemplate.queryForList(sql,new Object[]{userId});
        String leader_id ="";
        if(rlist.size()>0){
            for(int a=0;a<rlist.size();a++) {
                Map amap = (Map) rlist.get(a);
                leader_id = amap.get("leader_id") + "";
            }
        }
        //System.out.println("====JiangChao====leader_id: " + leader_id);
        return leader_id;
    }
    //根据呗转交人得id获取被转角人得姓名
    public String myTransferFlowLeaderName(String userId) {
        String sql = "SELECT scopevalue leader_id ,name leader_name,su.login_name FROM ldgx_scope LEFT  JOIN sys_user su ON su.id=scopevalue WHERE \"fielddatavalue\"=(SELECT f1 FROM ldgx WHERE f2 in(SELECT fielddatavalue FROM ldgx_scope WHERE \"scopevalue\"=?)) ";
        List<Map<String, Object>> rlist=jdbcTemplate.queryForList(sql,new Object[]{userId});
        String leader_name ="";
        if(rlist.size()>0){
            for(int a=0;a<rlist.size();a++) {
                Map amap = (Map) rlist.get(a);
                leader_name = amap.get("leader_name") + "";
            }
        }
        //System.out.println("====JiangChao====leader_name: " + leader_name);
        return leader_name;
    }
    //根据呗转交人得id获取被转角人得登录名
    public String myTransferFlowLeaderLoginName(String userId) {
        String sql = "SELECT scopevalue leader_id ,name leader_name,su.login_name FROM ldgx_scope LEFT  JOIN sys_user su ON su.id=scopevalue WHERE \"fielddatavalue\"=(SELECT f1 FROM ldgx WHERE f2 in(SELECT fielddatavalue FROM ldgx_scope WHERE \"scopevalue\"=?)) ";
        List<Map<String, Object>> rlist=jdbcTemplate.queryForList(sql,new Object[]{userId});
        String login_name ="";
        if(rlist.size()>0){
            for(int a=0;a<rlist.size();a++) {
                Map amap = (Map) rlist.get(a);
                login_name = amap.get("login_name") + "";
            }
        }
        //System.out.println("====JiangChao====login_name: " + login_name);
        return login_name;
    }
    //根据呗转交人得id获取被转角人得orgid
    public String myTransferFlowLeaderOrgId(String userId) {
        String sql = "SELECT scopevalue leader_id ,name leader_name,su.login_name,su.org_id FROM ldgx_scope LEFT  JOIN sys_user su ON su.id=scopevalue WHERE \"fielddatavalue\"=(SELECT f1 FROM ldgx WHERE f2 in(SELECT fielddatavalue FROM ldgx_scope WHERE \"scopevalue\"=?)) ";
        List<Map<String, Object>> rlist=jdbcTemplate.queryForList(sql,new Object[]{userId});
        String org_id ="";
        if(rlist.size()>0){
            for(int a=0;a<rlist.size();a++) {
                Map amap = (Map) rlist.get(a);
                org_id = amap.get("org_id") + "";
            }
        }
        //System.out.println("====JiangChao====org_id: " + org_id);
        return org_id;
    }

    /*public static void main(String[] args) throws Exception {
        ssoAuth2("srdyuga");
    }*/

    //获取临时token
    public static AccessToken getAccess_token()  throws Exception {
        String url="http://172.24.240.124:18088/flexbase/oauth2/token";
        Client client = new Client();
        String client_secret="CwSgxC3alRiODHUTeAxC";//
        String client_id="OwlcVZp96gbfQnjyOGH0";//
        Map<String, String> params = new HashMap<String, String>();
        params.put("client_id", client_id);
        params.put("client_secret", client_secret);
        params.put("grant_type", "client_credentials");
        AccessToken acctessToken = client.getToken(url, params);
        //System.out.println("====JiangChao====acctessToken: " + acctessToken.getAccessToken());
        return acctessToken;
    }

    //获取用户token
    public static  String   ssoAuth2(String leaderLoginName)  throws Exception {
        String url="http://172.24.240.124:18088/flexbase/api/system/logon/ssoAuth2";
        Client client = new Client();
        String token="";
        Map<String, String> params = new HashMap<String, String>();
        AccessToken acctessToken=getAccess_token();
        params.put("token ", acctessToken.getAccessToken());
        params.put("corpId", "0");
        params.put("loginType", "1");
        params.put("uid", leaderLoginName);
        String json = client.post(url, params, "", acctessToken);
        Map result = JsonUtils.readValue(json);
        if (result.get("type").toString().equals("success")) {
            Map data = (Map)result.get("data");
            token = StringUtils.null2String(data.get("token"));
            //System.out.println("====JiangChao====token: " + token);
        }
        return token;
    }
//20240726gaoyw秘书自定义转交获取领导待办列表-e


    @ApiOperation(value = "管理员流程转交", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignId", value = "转交人id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/transferTaskByAdmin", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult transferTaskByAdmin(String taskId, String assignId, String module, String comment, String commentType,
                                               String formType, String formId, String dataId, String processInstanceId, String permissionCode,
                                               HttpServletRequest request) {
        LOG.debug("transferTaskByAdmin    管理员流程转交...");

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String automaticReturn = request.getParameter("automaticReturn");
        String title = request.getParameter("processTitle");
        String commentId = request.getParameter("commentId");
        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        // 流程审批人
        if (StringUtils.isNotBlank(assignId)) {
            params.put("assignId", assignId);
        }
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        if (null != comment) {
            params.put("comment", comment);
            params.put("commentType", commentType);
            params.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                params.put("commentId", commentId);
            }
        }
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        bodyParams.put("automaticReturn", automaticReturn);
        permissionCode = module + ":" + permissionCode + ":zj";
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        LOG.debug("params:"+JsonUtils.writeValueAsString(params));
        LOG.debug("bodyParams:"+JsonUtils.writeValueAsString(bodyParams));
        String uid =pendingTaskService.getDoingUserIds(taskId);
        String json = approveApiClient.transferTaskByAdmin( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());//

        LOG.debug("json:"+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, uid, user.getCorpId(), user.getJwtToken());

                //ws刷新 add by V4.4 2023-7-18 14:31:14
               // WebsocketApproveConstant.refrashDealData(null);

            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {

            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程转交失败", e);
            return OperationResult.buildFailureResult("流程转交失败");
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程批量转交", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignId", value = "转交人id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assigneeNames", value = "转交人姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "automaticReturn", value = "是否自动返回", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/batchTransferTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult batchTransferTask(String taskId, String assignId, String module,
                                             String assigneeNames, String processInstanceId, String permissionCode, HttpServletRequest request) {
        LOG.debug("batchTransferTask   流程批量转交....");

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String automaticReturn = request.getParameter("automaticReturn");


        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        // 流程审批人
        if (StringUtils.isNotBlank(assignId)) {
            params.put("assignId", assignId);
            params.put("assigneeNames", assigneeNames);
        }
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskIds", taskId);
        params.put("autoback", automaticReturn);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        permissionCode = module + ":" + permissionCode + ":zj";
        List<Map> mapList = pendingTaskService.getTitleByProInsIds(Arrays.asList(processInstanceId.split(",")));
        List<Map> taskUserList=pendingTaskService.getDoingUserTaskList(Arrays.asList(taskId.split(",")));
        //根据任务id查询umc_message表
        List<String> msgIdList = pendingTaskService.getMsgIdByTaskId(taskId);
        String json = approveApiClient.batchTransferTask( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());
        LOG.debug("json:"+json);

        List<Map<String, String>> operateDataList = new ArrayList<Map<String, String>>();
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (mapList != null && mapList.size() > 0) {
                    for (Map ml : mapList) {
                        Map<String, String> operateDataMap = new HashMap<>();
                        operateDataMap.put("operateDetails", "");
                        operateDataMap.put("operateData", ml.get("title") + "");
                        operateDataMap.put("requestId", null);
                        operateDataList.add(operateDataMap);
                    }
                    logService.batchSaveModuleLog(permissionCode, operateDataList, request);
                }
                //删除umc_message
                pendingTaskService.deleteUmcMessById(msgIdList);
                for(Map ms : taskUserList){
                    pendingTaskService.gdingMsgDone(module, ms.get("taskId")+"", user.getCorpId(),ms.get("userId")+"", user.getJwtToken());
                    pendingTaskService.clearMsgDone( ms.get("processInstanceId")+"", module, ms.get("taskId")+"",user.getCorpId(), ms.get("userId")+"", user.getJwtToken());
                }
                //ws刷新 add by V4.4 2023-7-18 14:31:14
               // WebsocketApproveConstant.refrashDealData(null);

            } else {
                if (mapList != null && mapList.size() > 0) {
                    for (Map ml : mapList) {
                        Map<String, String> operateDataMap = new HashMap<>();
                        operateDataMap.put("operateDetails", "");
                        operateDataMap.put("operateData", ml.get("title") + "");
                        operateDataMap.put("requestId", UuidUtils.UUID());
                        operateDataList.add(operateDataMap);
                    }
                    logService.batchSaveModuleLog(permissionCode, operateDataList, request);
                }
            }
        } catch (Exception e) {
            LOG.error("流程批量转交失败", e);
            return OperationResult.buildFailureResult("流程批量转交失败");
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取流程按钮", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buttonCodes", value = "按钮编码", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getListButtonsByCodes", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getListButtonsByCodes(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String buttonCodes = request.getParameter("buttonCodes");

        return OperationResult.buildSuccessResult(pendingTaskService.getListButtonsByCodes(buttonCodes));
    }

    @ApiOperation(value = "发起流程获取按钮和表单字段的查看方式", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "流程code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "version", value = "流程版本", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getStartTaskInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getStartTaskInfo(String code, String version) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("code", code);
        params.put("version", version);
        String json = approveApiClient.getStartTaskInfo( params,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "下一活动信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "流程code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formData", value = "表单数据", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getNextActivity", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult getNextActivity(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        LOG.debug("开始  获取下一活动信息  getNextActivity ...");
        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        String dealCallMainProcess = StringUtils.null2String(request.getParameter("dealCallMainProcess"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        if(StringUtils.isBlank(taskId)){
            return OperationResult.buildFailureResult("参数taskId不能为空");
        }
        List<String> list = new ArrayList<>();
        if(StringUtils.isNotBlank(processInstanceId)){
            list.add("processInstanceId"+processInstanceId);
        }
        list.add("id"+taskId);//参数加密时用的是id  故此处不是taskId
        if(!"1".equals(dealCallMainProcess) && !ApproveSecUtils.verifyData(list,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String code = request.getParameter("code");
        String formData = request.getParameter("formData");

        String dataId = request.getParameter("dataId");
        String allEditIds = request.getParameter("allEditIds");
        String editType = request.getParameter("editType");
        String sourceType = request.getParameter("sourceType");

        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));

        WebUser user = WebUtils.getCurrentUser();
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(formData)) {
            bodyParams.put("userId", user.getUserId());
            try {
                bodyParams.put("formData", mapper.readValue(formData, Map.class));
            } catch (IOException e1) {
                LOG.error("处理formdata数据异常：", e1);
                return OperationResult.buildFailureResult("处理formdata数据异常");
            }
            bodyParams.put("editType", editType);
            bodyParams.put("allEditIds", allEditIds);
            bodyParams.put("dataId", dataId);
            bodyParams.put("commentInfoList", commentInfoList);
        }
        if (StringUtils.isNotBlank(sourceType)) {
            bodyParams.put("sourceType", sourceType);
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        bodyParams.put("orgId", orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            Map<String, String> params = new HashMap<String, String>();
            params.put("userId", user.getUserId());
            params.put("corpId", user.getCorpId());
            params.put("code", code);
            params.put("taskId", taskId);

            LOG.debug("getNextActivity   params:"+JSON.toJSONString(params));
            LOG.debug("getNextActivity   bodyDataParams:"+bodyDataParams);
            String json = approveApiClient.getNextActivity( params,bodyDataParams,user.getJwtToken());
            LOG.debug("getNextActivity   json:"+json);
            this.approveCacheService.setNextActivityCache(taskId,json);

            if(StringUtils.isNotBlank(json)){
                Map map=JsonUtils.readValue(json);
                if(StringUtils.equals("success", map.get("type")+"")){
                    if(map.get("data") instanceof Map){
                        Map dataMap = (Map)map.get("data");
                        String callMainProInsId = StringUtils.null2String(dataMap.get("callMainProInsId"));
                        String callMainTaskId = StringUtils.null2String(dataMap.get("callMainTaskId"));
                        if(StringUtils.isNotBlank(callMainProInsId) && StringUtils.isNotBlank(callMainTaskId)){
                            dataMap.put("processInstanceId",callMainProInsId);
                            dataMap.put("id",callMainTaskId);
                            dataMap = ApproveSecUtils.encryptData(dataMap,"processInstanceId,id");
                        }
                        return OperationResult.buildSuccessResult(dataMap);
                    }else{
                        return pendingTaskService.stringToOperation(json);
                    }

                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
            }
            return OperationResult.buildFailureResult("参数不能为空");
        } catch (Exception e) {
            LOG.error("获取下一活动信息失败", e);
        }
        return OperationResult.buildFailureResult("节点参与者或网关条件设置不正确，请重新设置");

    }

    @ApiOperation(value = "签收任务", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "unlock", value = "解锁 标识1", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/claimTask", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult claimTask(String taskId, String unlock) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("unlock", unlock);
        String json = approveApiClient.claimTask( params,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    //20240729gaoyw  秘书转交领导待办之前先要进行一下签收，不然不让转交-s
    @ApiOperation(value = "签收任务", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "unlock", value = "解锁 标识1", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/myClaimTask", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult myClaimTask(String taskId,String userId, String unlock,String token) {
//        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);
        params.put("corpId", "0");
        params.put("taskId", taskId);
        params.put("unlock", unlock);
        String json = approveApiClient.claimTask( params,token);
        return pendingTaskService.stringToOperation(json);
    }
    //20240729gaoyw  秘书转交领导待办之前先要进行一下签收，不然不让转交-e

    @ApiOperation(value = "获取驳回节点", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "backType", value = "驳回类型", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getCanBackActivity", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getCanBackActivity(HttpServletRequest request,String taskId, String backType) {
        LOG.debug("getCanBackActivity    获取驳回节点...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("backType", backType);

        LOG.debug("params:"+JsonUtils.writeValueAsString(params));
        String json = approveApiClient.getCanBackActivity( params,user.getJwtToken());
        Map map = JsonUtils.readValue(json);
        if (StringUtils.equals("success", map.get("type") + "")) {
            Map data = (Map) map.get("data");
            List<Map<String, Object>> list = (List) data.get("list");
            String participantMode = data.get("participantMode") + "";
            List<Map<String, Object>> newList = new ArrayList();
            Map<String,Map> newMap = new LinkedHashMap();
            for(Map ma:list){
                if(null==newMap.get(ma.get("id"))){
                    Map map1 = new HashMap();
                    map1.put("id",ma.get("id"));
                    map1.put("name",ma.get("name"));
                    map1.put("warningField", ma.get("warningField"));
                    List li = new ArrayList();
                    Map m3 = new HashMap();
                    m3.put("userId", ma.get("participants"));
                    m3.put("userName", ma.get("participantNames"));
                    li.add(m3);
                    map1.put("userList", li);
                    newMap.put(ma.get("id").toString(),map1);
                }else{
                    Map map1=newMap.get(ma.get("id"));
                    List userList = (List) map1.get("userList");
                    Map m3 = new HashMap();
                    m3.put("userId", ma.get("participants"));
                    m3.put("userName", ma.get("participantNames"));
                    userList.add(m3);
                }
            }
            for (Map.Entry<String, Map> entry : newMap.entrySet()){
                newList.add(entry.getValue());
            }

            Map ma = new HashMap();
            ma.put("participantMode", participantMode);
            ma.put("list", newList);
            return OperationResult.buildSuccessResult(ma);
        }
        return OperationResult.buildFailureResult(map.get("message") + "", map.get("data"));
    }

    @ApiOperation(value = "流程退回", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetId", value = "退回节点", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "backType", value = "退回类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式  0-单人 1-会签 2-串签 3-抢占", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "backReasonText", value = "退回原因", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserId", value = "节点用户id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserName", value = "节点用户姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetName", value = "节点名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deadline", value = "截止时间", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/back", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult back(String taskId, String targetId, String backType, String module, String processInstanceId,
                                String formType, String participantMode, String comment, String commentType, String permissionCode,
                                String backReasonText, String targetUserId, String targetUserName, String targetName, String formId,
                                String dataId, String reminders, String reminderContent, String processTitle, HttpServletRequest request) {
        LOG.debug("开始  流程退回   back:");

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String designActivity = request.getParameter("designActivity");
        String commentId = request.getParameter("commentId");
        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String deadline = StringUtils.null2String(request.getParameter("deadline"));
        String sapJson = StringUtils.null2String(request.getParameter("sapJson"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        String userId = user.getUserId();
        params.put("userId", userId);
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        params.put("targetId", targetId);
        params.put("targetName", targetName);
        params.put("backType", backType);
        params.put("backReasonText", backReasonText);
        if (comment != null) {
            params.put("comment", comment);
            params.put("commentType", commentType);
            params.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                params.put("commentId", commentId);
            }
        }
        if (StringUtils.isNotBlank(targetUserId)) {
            params.put("targetUserId", targetUserId);
            params.put("targetUserName", targetUserName);
        }

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }

        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        Map m1 = new HashMap();
        m1.put("reminderContent", reminderContent);
        m1.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m1));

        bodyParams.put("deadline", deadline);

        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        bodyParams.put("sapJson",sapJson);//sap参数

        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        permissionCode = module + ":" + permissionCode + ":bh";
        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);
        List<Map> mapList = new ArrayList<>();
        ArrayList<String> receiver=new ArrayList<>();
        if (null != list && list.size() > 0) {
            if (StringUtils.isBlank(targetUserId)) {
                List<Map> tarList = pendingTaskService.getTaskAndUser(processInstanceId, targetId);
                if (null != tarList && tarList.size() > 0) {
                    for (Map tm : tarList) {
                        targetUserId = targetUserId + "," + tm.get("userId") + ",";
                    }
                }
            }
            targetUserId = "," + targetUserId + "," + userId + ",";
            for (Map maps : list) {
                if (targetUserId.indexOf(maps.get("userId") + "") >= 0) {
                    continue;
                }
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("dataId", dataId);
                m.put("formId", formId);
                m.put("module", module);
                m.put("processTitle", processTitle);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "退回");
                m.put("messageContent", backReasonText);
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程退回提醒");
                mapList.add(m);
                receiver.add(maps.get("userId") + "");
            }
        }
        LOG.debug("back   params:"+JSON.toJSONString(params));
        LOG.debug("back   bodyString:"+bodyString);
        String json = approveApiClient.back( params,bodyString,user.getJwtToken());
        LOG.debug("back   json:"+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, processTitle, null);
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
                List<Map> doingList = pendingTaskService.getTaskAndUser(processInstanceId, targetId);
                String taskIds="";
                for(Map m:doingList){
                    taskIds=taskIds+","+m.get("taskId");
                }
                pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), backReasonText,
                        "1", taskIds);
                pendingTaskService.sendReminder(mapList, user.getJwtToken());
                //删除其他平级节点任务
                List<String> deleteDoingTaskId = (List<String>) map.get("data");
                if(null!=deleteDoingTaskId && deleteDoingTaskId.size()>0){
                    deleteDoingTaskId.remove(taskId);
                    pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), StringUtils.collectionToDelimitedString(deleteDoingTaskId,","), user.getJwtToken(), module);
                }

                /** 清理办理人信息的缓存 **/
                this.pendingTaskService.delApproveDealUserCache("[{\"id\":\""+targetId+"\"}]",taskId);

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);

                /** 清理办理人正文锁信息 **/
                this.bpmProcessTextlockService.delTextlock(userId,processInstanceId);

            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, processTitle, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, processTitle, null, UuidUtils.UUID());
            }
            LOG.error("退回失败", e);
            return OperationResult.buildFailureResult("退回失败");
        }
        LOG.debug("结束  back");
        receiver.add(userId);
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
               // WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = "发起流程", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "流程code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "version", value = "流程版本", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "parentProcessInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "parentTaskId", value = "父任务id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/startVerifyProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult startVerifyProcess(HttpServletRequest request,String code, String version, String parentProcessInstanceId, String parentTaskId) {
        LOG.debug("开始发起流程  startVerifyProcess  code="+code);

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("code"+code,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        String orgName = user.getCurrentPtOrgName();
        String userName = user.getCnName();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
            orgName = user.getOrgName();
        }

        params.put("groupId", orgId);
        params.put("code", code);
        if (StringUtils.isNotBlank(version)) {
            params.put("version", version);
        }
        if (StringUtils.isNotBlank(parentProcessInstanceId)) {
            bodyParams.put("parentProcessInstanceId", parentProcessInstanceId);
        }
        if (StringUtils.isNotBlank(parentTaskId)) {
            bodyParams.put("parentTaskId", parentTaskId);
        }

        bodyParams.put("orgName", orgName);
        bodyParams.put("userName", userName);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        LOG.debug("startProcess  params="+JSON.toJSONString(params));

        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            LOG.debug("startProcess  bodyDataParams="+bodyDataParams);
            String json = approveApiClient.startProcess( params,bodyDataParams,user.getJwtToken());
            LOG.debug("startProcess  json="+json);
            LOG.debug("结束发起流程    startProcess");
            if(StringUtils.isNotBlank(json)){
                Map map = JsonUtils.readValue(json);

                if(StringUtils.equals("success", map.get("type")+"")){
                    Map data = (Map)map.get("data");
                    String id = StringUtils.null2String(data.get("openTaskId"));
                    data.put("id", id);
                    ApproveSecUtils.encryptData(data,"processInstanceId,id");

                    List<String> receiver = new ArrayList<>();
                    receiver.add(user.getUserId());

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                   // WebsocketApproveConstant.refrashDealData(receiver);

                    return OperationResult.buildSuccessResult(data);
                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
            }
            return OperationResult.buildFailureResult("参数不能为空");
        } catch (JsonProcessingException e) {
            LOG.error("启动流程失败", e);
            return OperationResult.buildFailureResult("启动流程失败");
        }
    }

    @ApiOperation(value = "发起流程", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "流程code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "version", value = "流程版本", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "parentProcessInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "parentTaskId", value = "父任务id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/startProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult startProcess(HttpServletRequest request,String code, String version, String parentProcessInstanceId, String parentTaskId) {
        LOG.debug("开始发起流程  startProcess  code="+code);

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        String orgName = user.getCurrentPtOrgName();
        String userName = user.getCnName();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
            orgName = user.getOrgName();
        }

        params.put("groupId", orgId);
        params.put("code", ValidateUtils.filter(code));
        if (StringUtils.isNotBlank(version)) {
            params.put("version", version);
        }
        if (StringUtils.isNotBlank(parentProcessInstanceId)) {
            bodyParams.put("parentProcessInstanceId", parentProcessInstanceId);
        }
        if (StringUtils.isNotBlank(parentTaskId)) {
            bodyParams.put("parentTaskId", parentTaskId);
        }

        bodyParams.put("orgName", orgName);
        bodyParams.put("userName", userName);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        LOG.debug("startProcess  params="+JSON.toJSONString(params));

        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            LOG.debug("startProcess  bodyDataParams="+bodyDataParams);
            String json = approveApiClient.startProcess( params,bodyDataParams,user.getJwtToken());
            LOG.debug("startProcess  json="+json);
            LOG.debug("结束发起流程    startProcess");
            if(StringUtils.isNotBlank(json)){
                Map map = JsonUtils.readValue(json);

                if(StringUtils.equals("success", map.get("type")+"")){
                    Map data = (Map)map.get("data");
                    String id = StringUtils.null2String(data.get("openTaskId"));
                    data.put("id", id);
                    ApproveSecUtils.encryptData(data,"processInstanceId,id");

                    return OperationResult.buildSuccessResult(data);
                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
            }
            return OperationResult.buildFailureResult("参数不能为空");
        } catch (JsonProcessingException e) {
            LOG.error("启动流程失败", e);
            return OperationResult.buildFailureResult("启动流程失败");
        }
    }

    @ApiOperation(value = "保存任务", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formData", value = "表单数据", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "编辑字段", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "secretLevel", value = "密级", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "新的批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "titleSetValue", value = "标题设置", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgentField", value = "紧急程度", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isEndSave", value = "是否办结保存 1是", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/saveTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult saveTask(HttpServletRequest request, String formData, String editType, String allEditIds, String dataId, String taskId,
                                    String formType, String module, String permissionCode, String processInstanceId, String comment,
                                    String commentType, String commentId, String secretLevel) {
        LOG.debug("开始  保存任务    saveTask");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        //新的批示意见集合
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        //标题设置
        String titleSetValue = StringUtils.null2String(request.getParameter("titleSetValue"));
        //紧急程度
        String urgentField = StringUtils.null2String(request.getParameter("urgentField"));
        //是否办结保存 1是
        String isEndSave = StringUtils.null2String(request.getParameter("isEndSave"));

        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("userId", user.getUserId());
        bodyParams.put("titleSetValue", titleSetValue);
        bodyParams.put("urgentField", urgentField);
        try {
            bodyParams.put("formData", mapper.readValue(formData, Map.class));
        } catch (IOException e1) {
            LOG.error("处理formdata数据异常：", e1);
            return OperationResult.buildFailureResult("处理formdata数据异常");
        }
        if (StringUtils.equals("readd", editType)) {
            editType = "add";
            dataId = "";
        }
        bodyParams.put("isEndSave", isEndSave);
        bodyParams.put("permissionCode", permissionCode);
        bodyParams.put("editType", editType);
        bodyParams.put("allEditIds", ValidateUtils.filter(allEditIds));
        bodyParams.put("dataId", ValidateUtils.filter(dataId));
        bodyParams.put("formType", ValidateUtils.filter(formType));
        bodyParams.put("moduleCode",module);
        if (null != comment) {
            bodyParams.put("comment", comment);
            bodyParams.put("commentType", commentType);
            bodyParams.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                bodyParams.put("commentId", commentId);
            }
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        boolean logEnable = false;
        String logCode = "";
        logCode = module + ":" + permissionCode + ":02";
        if (StringUtils.equals("draft", permissionCode)) {
            logCode = module + ":" + permissionCode + ":bc";
        }

        logEnable = logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken());
        Map<String, String> rmap = new HashMap<String, String>();
        rmap.put("logEnable", logEnable ? "1" : "0");
        bodyParams.put("extParam", JsonUtils.writeValueAsString(rmap));
        if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
            bodyParams.put("secretLevel", secretLevel);
        }
        String title = pendingTaskService.getTitleByProInsId(processInstanceId);
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        params.put("processInstanceId", processInstanceId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            LOG.debug("saveTask     params："+JSON.toJSONString(params));
            LOG.debug("saveTask     bodyDataParams："+bodyDataParams);

            String json = approveApiClient.saveTask( params,bodyDataParams,user.getJwtToken());
            LOG.debug("saveTask     json："+json);
            try {
                Map<String, Object> map = mapper.readValue(json, Map.class);
                if ("success".equals(map.get("type").toString())) {
                    Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
                    if (StringUtils.isBlank(dataId)) {
                        dataId = dataMap.get("dataId") + "";
                    }
                    if (logEnable) {
                        String modiInfo = "";
                        if (null != dataMap && null != dataMap.get("modiInfo")) {
                            modiInfo = dataMap.get("modiInfo") + "";
                        }
                        logService.saveModuleLog(logCode, title, modiInfo);
                    }
                    if (GlobalConstant.isUseSecretLevel() && StringUtils.isNotBlank(secretLevel)) {
                        bpmProcessExtendService.updateProcessExtend(processInstanceId, secretLevel);
                    }

                    Map<String, Object> formMap = JsonUtils.readValue(formData);
                    String formId = formMap.get("formId") + "";
                    if (StringUtils.isBlank(dataId)) {
                        dataId = pendingTaskService.getBusiIdByProInsId(processInstanceId);
                    }
                    if(!StringUtils.equals("1",isEndSave)){
                        if (StringUtils.equals("draft", permissionCode) || StringUtils.equals("start", permissionCode)){
                            pendingTaskService.insertUpdateFormSql("-1", true, formId, dataId, processInstanceId);
                        }else{
                            pendingTaskService.insertUpdateFormSql("0", true, formId, dataId, processInstanceId);
                        }
                    }
                } else {
                    LOG.debug("saveTask  任务保存失败  json："+json);
                    if (logEnable) {
                        logService.saveModuleLog(logCode, title, "", UuidUtils.UUID());
                    }
                }
            } catch (Exception e) {
                LOG.error("保存任务失败", e);
                if (StringUtils.isNotBlank(dataId)) {
                    if (logEnable) {
                        logService.saveModuleLog(logCode, title, "", UuidUtils.UUID());
                    }
                }
            }
            LOG.debug("结束    保存任务    saveTask");

            ArrayList<String> receiver=new ArrayList<>();
            receiver.add(user.getUserId());
            if(StringUtils.isNotBlank(json)){
                Map map=JsonUtils.readValue(json);
                if(StringUtils.equals("success", map.get("type")+"")){
                    WebsocketUtils.setReceiverById(receiver);

                    try{
                        //ws刷新 add by V4.4 2023-7-18 14:31:14
                        WebsocketUtils.sendMessageByIds(receiver, WebsocketConstant.MSGUNITEDAPPROVE+","+WebsocketConstant.UNITEDAPPROVE+","+WebsocketConstant.APPROVE);
                    }catch(Exception e){
                        LOG.error("ws 刷新报错：",e);
                    }

                    return OperationResult.buildSuccessResult(map.get("data"));
                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
            }else{
                return OperationResult.buildFailureResult("参数不能为空");
            }
        } catch (Exception e) {
            LOG.error("保存任务失败", e);
            if (StringUtils.isNotBlank(dataId)) {
                if (logEnable) {
                    logService.saveModuleLog(logCode, title, "", UuidUtils.UUID());
                }
            }
            return OperationResult.buildFailureResult("保存任务失败");
        }
    }

    @ApiOperation(value = "流程结束", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryCode", value = "流程分类编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endReasonText", value = "强制结束原因", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endReasonType", value = "强制结束原因类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/forceEnd", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult forceEnd(String processInstanceId, String taskId, String module, String menuType,
                                    String participantMode, String permissionCode, HttpServletRequest request) {
        LOG.debug("forceEnd    结束任务...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderObject = request.getParameter("reminderObject");
        String designActivity = request.getParameter("designActivity");
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String categoryCode = request.getParameter("categoryCode");
        String formId = request.getParameter("formId");
        String dataId = request.getParameter("dataId");
        String endReasonText =StringUtils.null2String(request.getParameter("endReasonText"));
        String endReasonType =StringUtils.null2String(request.getParameter("endReasonType"));
        //公文查询记录操作日志
        String logModule = StringUtils.null2String(request.getParameter("logModule"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        String logCode = module + ":" + permissionCode + ":js";
        String sapJson = StringUtils.null2String(request.getParameter("sapJson"));

        /**
         * 公文查询 操作日志记录 特殊处理
         *  发文查询：
         *      sendFile:flowQuery:js   结束
         *      sendFile:flowQuery:dy   打印
         *      sendFile:flowQuery:tz   跳转
         *  收文查询：
         *       receiveFile:flowQuery:js   结束
         *       receiveFile:flowQuery:dy   打印
         *       receiveFile:flowQuery:tz   跳转
         *  签报查询：
         *       signReport:flowQuery:js   结束
         *       signReport:flowQuery:dy   打印
         *       signReport:flowQuery:tz   跳转
         *
         */
        if("goa_document".equals(module)){
            //流程查询
            if("flowQuery".equals(permissionCode) && StringUtils.isNotBlank(logModule)){
                logCode = logModule + ":" + permissionCode + ":js";
            }
        }

        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);
        List<Map> mapList = new ArrayList<>();
        ArrayList<String> receiver=new ArrayList<>();
        if (null != list && list.size() > 0) {
            String messageContent = "该流程已结束";
            //勾选“作为提醒内容”
            if (endReasonType.indexOf("2") > -1) {
                messageContent = endReasonText;
            }
            for (Map maps : list) {
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("categoryCode", categoryCode);
                m.put("dataId", dataId);
                m.put("formId", formId);
                m.put("module", module);
                m.put("processTitle", title);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "结束");
                m.put("messageContent", messageContent);
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程结束提醒");
                mapList.add(m);
                receiver.add(maps.get("userId") + "");
            }
        }
        List<Map> allTaskUserList = pendingTaskService.getTaskAndUser(processInstanceId, null);

        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("sapJson", sapJson);
        bodyParams.put("endReasonType", endReasonType);
        bodyParams.put("endReasonText", endReasonText);
        String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);

        LOG.debug("forceEnd    params="+JSON.toJSONString(params));
        String json = approveApiClient.forceEnd( params,bodyDataParams,user.getJwtToken());
        LOG.debug("forceEnd    json="+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                    logService.saveModuleLog(logCode, title, null);
                }
                for(Map m:allTaskUserList){
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, m, m.get("userId")+"", user.getCorpId(), user.getJwtToken());

                }
                pendingTaskService.updateFormSqlByProInsId(processInstanceId);

                pendingTaskService.sendReminder(mapList, user.getJwtToken());
            } else {
                if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                    logService.saveModuleLog(logCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                logService.saveModuleLog(logCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程结束失败", e);
        }

        LOG.debug("结束    结束任务    forceEnd");


        receiver.add(user.getUserId());
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = "流程结束", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "提醒对象：1-指定环节办理人  2-所有环节办理人", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式： 1-短信  2-移动端 3-系统提醒 4-邮件提醒", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryCode", value = "流程分类编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endReasonText", value = "强制结束原因", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endReasonType", value = "强制结束原因类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/forceEndByAdmin", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult forceEndByAdmin(String processInstanceId, String module, String menuType,
                                           String permissionCode, HttpServletRequest request) {
        LOG.debug("forceEndByAdmin    流程结束...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderObject = request.getParameter("reminderObject");
        String designActivity = request.getParameter("designActivity");
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String categoryCode = request.getParameter("categoryCode");
        String formId = request.getParameter("formId");
        String dataId = request.getParameter("dataId");
        String endReasonText =StringUtils.null2String(request.getParameter("endReasonText"));
        String endReasonType =StringUtils.null2String(request.getParameter("endReasonType"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("processInstanceId", processInstanceId);

        params.put("endReasonType", endReasonType);
        params.put("endReasonText", endReasonText);
        //公文查询记录操作日志
        String logModule = StringUtils.null2String(request.getParameter("logModule"));

        String logCode = module + ":" + permissionCode + ":js";

        /**
         * 公文查询 操作日志记录 特殊处理
         *  发文查询：
         *      sendFile:flowQuery:js   结束
         *      sendFile:flowQuery:dy   打印
         *      sendFile:flowQuery:tz   跳转
         *  收文查询：
         *       receiveFile:flowQuery:js   结束
         *       receiveFile:flowQuery:dy   打印
         *       receiveFile:flowQuery:tz   跳转
         *  签报查询：
         *       signReport:flowQuery:js   结束
         *       signReport:flowQuery:dy   打印
         *       signReport:flowQuery:tz   跳转
         *
         */
        if("goa_document".equals(module)){
            //流程查询
            if("flowQuery".equals(permissionCode) && StringUtils.isNotBlank(logModule)){
                logCode = logModule + ":" + permissionCode + ":js";
            }
        }
        LOG.debug("forceEndByAdmin    logCode:"+logCode);
        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);
        List<Map> mapList = new ArrayList<>();
        List<String> receiver = new ArrayList<>();
        if (null != list && list.size() > 0) {
            String messageContent = "该流程已结束";
            if (endReasonType.indexOf("2") > -1) {
                messageContent = endReasonText;
            }
            for (Map maps : list) {
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("categoryCode", categoryCode);
                m.put("dataId", dataId);
                m.put("formId", formId);
                m.put("module", module);
                m.put("processTitle", title);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "结束");
                m.put("messageContent", messageContent);
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程结束提醒");
                mapList.add(m);
                receiver.add(StringUtils.null2String(maps.get("userId")));
            }
        }
        List<Map> allTaskUserList = pendingTaskService.getTaskAndUser(processInstanceId, null);
        String json = approveApiClient.forceEndByAdmin( params,user.getJwtToken());
        ObjectMapper mapper = new ObjectMapper();
        try {
            Map<String, Object> map = mapper.readValue(json, Map.class);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                    logService.saveModuleLog(logCode, title, null);
                }
                for(Map m:allTaskUserList){
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, m, m.get("userId")+"", user.getCorpId(), user.getJwtToken());
                }
                pendingTaskService.updateFormSqlByProInsId(processInstanceId);

                pendingTaskService.sendReminder(mapList, user.getJwtToken());

                receiver.add(user.getUserId());

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

            } else {
                if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                    logService.saveModuleLog(logCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
                logService.saveModuleLog(logCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程结束失败", e);
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程撤销", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userIds", value = "用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userNames", value = "用户名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskNames", value = "任务名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryCode", value = "流程分类编码", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/recall", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult recall(String taskId, String module, String processInstanceId, String formId, String dataId,
                                  String formType, String permissionCode, HttpServletRequest request) {
        LOG.debug("recall    流程撤销...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String taskIds = request.getParameter("taskIds");
        String title = request.getParameter("processTitle");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        permissionCode = module + ":" + permissionCode + ":cx";
        List<Map> tskUserList = new ArrayList<Map>();
        String tids[] = taskIds.split(",");
        for(String tid : tids){
            Map<String, String> ms = new HashMap<String, String>();
            ms.put("taskId", tid);
            String uid = pendingTaskService.getDoingUserIds(tid);
            ms.put("userId", uid);
            tskUserList.add(ms);
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        String json = approveApiClient.recall( params,user.getJwtToken());
        ObjectMapper mapper = new ObjectMapper();
        try {
            Map<String, Object> map = mapper.readValue(json, Map.class);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }

                String newTaskIds = pendingTaskService.getAllTaskIds(processInstanceId);
                newTaskIds=","+newTaskIds+",";
                String newTids="";
                for(Map m1 : tskUserList){
                    String tid=m1.get("taskId")+"";
                    if(newTaskIds.indexOf(","+tid+",")==-1){
                        newTids=newTids+","+tid;
                        pendingTaskService.clearMsgDone( processInstanceId, module, tid,
                                user.getCorpId(),m1.get("userId")+"", user.getJwtToken());
                    }
                }
                /** 流程撤回 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                //删除消息
                pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), taskId+newTids , user.getJwtToken(), module);

                //发消息
                Map<String, String> m = new HashMap<String, String>();
                m.put("typeName", "撤回");
                m.put("messageContent", "该流程已撤回");
                String userIds = request.getParameter("userIds");
                String userNames = request.getParameter("userNames");
                String taskNames = request.getParameter("taskNames");
                String reminderContent = request.getParameter("reminderContent");
                String reminders = request.getParameter("reminders");
                String categoryCode = request.getParameter("categoryCode");
                m.put("userIds", userIds);
                m.put("userNames", userNames);
                m.put("taskIds", taskIds);
                m.put("taskNames", taskNames);
                m.put("reminderContent", reminderContent);
                m.put("module", module);
                m.put("reminders", reminders);
                m.put("processInstanceId", processInstanceId);
                m.put("categoryCode", categoryCode);
                m.put("formId", formId);
                m.put("dataId", dataId);
                m.put("processTitle", title);
                m.put("categoryCode", categoryCode);
                m.put("orgId", orgId);
                m.put("taskType", "5");
                m.put("msgTitle", "流程撤回提醒");
                m.put("officeFullPath", GlobalConstant.getFlexOfficeFullPath(request));
                pendingTaskService.sendNoticeSleep(m, request, user);
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程撤回失败", e);
        }

        String userIds = request.getParameter("userIds");
        String[] split = userIds.split(",");
        ArrayList<String> receiver=new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i]);
        }
        receiver.add(user.getUserId());
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = "获取流程跟踪", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowComment", value = "是否显示批示意见 1是", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getProcessTrackInfo", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult getProcessTrackInfo(String taskId, String processInstanceId,String isShowComment,HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("processInstanceId", processInstanceId);
        params.put("isShowComment", isShowComment);
        String formData =  request.getParameter("formData");
        Map m = new HashMap();
        m.put("formData",JsonUtils.readValue(formData));
        String json = approveApiClient.getProcessTrackInfo( params,JsonUtils.writeValueAsString(m),user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "阅毕任务", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formData", value = "表单数据", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "titleSetValue", value = "流程标题", required = false, paramType = "query", dataType = "String"),

    })
    @RequestMapping(value = "/readCompleteTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult readCompleteTask(HttpServletRequest request,String processInstanceId,
                                            String taskId, String module, String permissionCode) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String titleSetValue = StringUtils.null2String(request.getParameter("titleSetValue"));

        WebUser user = WebUtils.getCurrentUser();
        permissionCode = ValidateUtils.filter(permissionCode);
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("userId", user.getUserId());

        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("taskId", taskId);
        params.put("module", module);
        permissionCode = module + ":" + permissionCode + ":yy";
        String title = titleSetValue;
        if(StringUtils.isBlank(title)){
            title = pendingTaskService.getTitleByProInsId(processInstanceId);
        }
        try {
            bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
            bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

            String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
            String json = approveApiClient.readCompleteTask( params,bodyDataParams,user.getJwtToken());
            try {
                Map<String, Object> map =  JsonUtils.readValue(json);
                if ("success".equals(map.get("type").toString())) {
                    // 完成消息
                    pendingTaskService.updateReadUmcMessageStatus(taskId);
                    pendingTaskService.takeReadMsgDone(module, taskId, user.getCorpId(), user.getUserId(), user.getJwtToken());
                    if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                        logService.saveModuleLog(permissionCode, title, null);
                    }
                } else {
                    if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                        logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                    }
                }
            } catch (Exception e) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
                LOG.error("阅毕失败", e);
            }
            ArrayList<String> receiver=new ArrayList<>();
            receiver.add(user.getUserId());
            if(StringUtils.isNotBlank(json)){
                Map map=JsonUtils.readValue(json);
                if(StringUtils.equals("success", map.get("type")+"")){

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                    WebsocketApproveConstant.refrashDealData(receiver);

                    return OperationResult.buildSuccessResult(map.get("data"));
                }
                return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
            }else{
                return OperationResult.buildFailureResult("参数不能为空");
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("阅毕失败", e);
            return OperationResult.buildFailureResult("阅毕失败");
        }
    }

    @ApiOperation(value = "加签", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignees", value = "加签用户id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "automaticReturn", value = "是否自动返回 1-是", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assigneeNames", value = "加签用户名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isRepeat", value = "是否重复判断 1否", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/addSign", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult addSign(String taskId, String assignees, String module,String permissionCode, String processInstanceId,
                                   HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String automaticReturn = request.getParameter("automaticReturn");
        String title = request.getParameter("processTitle");
        String assigneeNames = request.getParameter("assigneeNames");
        String isRepeat = request.getParameter("isRepeat");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("assignees", assignees);
        params.put("assigneeNames", assigneeNames);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        if (StringUtils.isNotBlank(reminderContent) && !"null".equals(reminderContent) && !"undefined".equals(reminderContent)) {
            Map m = new HashMap();
            m.put("reminderContent", reminderContent);
            m.put("orgId", orgId);
            bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        }

        bodyParams.put("isRepeat", isRepeat);
        bodyParams.put("automaticReturn", automaticReturn);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        permissionCode = module + ":" + permissionCode + ":jq";
        String json = approveApiClient.addSign( params,bodyString,user.getJwtToken());
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("加签失败", e);
            return OperationResult.buildFailureResult("加签失败");
        }
        ArrayList<String> receiver=new ArrayList<>();
        String[] split = assignees.split(",");
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i]);
        }
        receiver.add(user.getUserId());
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = " 获取可跳转节点信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getCanJumpActivity", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getCanJumpActivity(String taskId) {

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        String json = approveApiClient.getCanJumpActivity( params,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程跳转", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formData", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "editType", value = "编辑类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "allEditIds", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "selectedActivity", value = "所选任务", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "auditorUserIds", value = "审批人ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "shortMessage", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentType", value = "批示意见类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgency", value = "紧急", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentOrgId", value = "批示意见组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见集合", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/jump", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult jump(String formData, String editType, String allEditIds, String dataId, String formType,
                                String processInstanceId, String menuType, String taskId, String selectedActivity, String auditorUserIds,
                                String module, String shortMessage, String comment, String commentType,
                                String permissionCode, String commentId, HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        //批示意见组织id
        String commentOrgId = StringUtils.null2String(request.getParameter("commentOrgId"));
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));

        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("userId", userId);
        try {
            bodyParams.put("formData", mapper.readValue(formData, Map.class));
        } catch (Exception e1) {
            LOG.error("处理formdata数据异常：" , e1.getMessage());
            return OperationResult.buildFailureResult("");
        }
        bodyParams.put("editType", editType);
        bodyParams.put("allEditIds", allEditIds);
        bodyParams.put("dataId", dataId);
        bodyParams.put("formType", formType);
        bodyParams.put("selectedActivity", selectedActivity);
        bodyParams.put("auditorUserIds", auditorUserIds);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        //公文查询记录操作日志
        String logModule = StringUtils.null2String(request.getParameter("logModule"));
        String logCode = module + ":" + permissionCode + ":tz";

        /**
         * 公文查询 操作日志记录 特殊处理
         *  发文查询：
         *      sendFile:flowQuery:js   结束
         *      sendFile:flowQuery:dy   打印
         *      sendFile:flowQuery:tz   跳转
         *  收文查询：
         *       receiveFile:flowQuery:js   结束
         *       receiveFile:flowQuery:dy   打印
         *       receiveFile:flowQuery:tz   跳转
         *  签报查询：
         *       signReport:flowQuery:js   结束
         *       signReport:flowQuery:dy   打印
         *       signReport:flowQuery:tz   跳转
         *
         */
        if("goa_document".equals(module)){
            //流程查询
            if("flowQuery".equals(permissionCode) && StringUtils.isNotBlank(logModule)){
                logCode = logModule + ":" + permissionCode + ":tz";
            }
        }

        boolean logEnable = logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken());
        Map<String, String> rmap = new HashMap<String, String>();
        rmap.put("logEnable", logEnable ? "1" : "0");
        bodyParams.put("extParam", JsonUtils.writeValueAsString(rmap));
        if (comment != null) {
            bodyParams.put("comment", comment);
            bodyParams.put("commentType", commentType);
            bodyParams.put("commentOrgId", commentOrgId);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                bodyParams.put("commentId", commentId);
            }
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        if (StringUtils.isNotBlank(shortMessage) && !"null".equals(shortMessage) && !"undefined".equals(shortMessage)) {
            bodyParams.put("msgType", shortMessage);
        }
        String title = pendingTaskService.getTitleByProInsId(processInstanceId);
        Map m = new HashMap();
        m.put("reminderContent", title + "需要您办理");
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);
        params.put("corpId", user.getCorpId());
        params.put("groupId", orgId);
        params.put("taskId", taskId);

        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            String json = "";
            String taskIds = pendingTaskService.getAllTaskIdsByTaskId(userId,  user.getCorpId(), taskId, user.getJwtToken());
            if ("query".equals(menuType)) {
                json = approveApiClient.jumpByAdmin( params,bodyDataParams,user.getJwtToken());//
            }else{
                json = approveApiClient.jump( params,bodyDataParams,user.getJwtToken());//
            }
            Map<String, Object> map = mapper.readValue(json, Map.class);
            if ("success".equals(map.get("type").toString())) {
                if (logEnable) {
                    logService.saveModuleLog(logCode, title, "");
                }
                Map<String, String> ms = new HashMap<String, String>();
                if(StringUtils.isBlank(taskIds)){
                    ms.put("taskId", taskId);
                    taskIds=taskId;
                }else{
                    ms.put("taskId", taskIds);
                }
                if ("query".equals(menuType)){
                    pendingTaskService.deleteMessages(userId, user.getCorpId(),taskIds, user.getJwtToken(),module);
                }else{
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, userId, user.getCorpId(), user.getJwtToken());
                }

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                /** 清理办理人正文锁信息 **/
                bpmProcessTextlockService.delTextlock(userId,processInstanceId);
            } else {
                if (logEnable) {
                    logService.saveModuleLog(logCode, title, "", UuidUtils.UUID());
                }
            }
            String[] split = auditorUserIds.split(",");
            ArrayList<String> receiver=new ArrayList<>();
            for (int i = 0; i < split.length; i++) {
                receiver.add(split[i]);
            }
            receiver.add(user.getUserId());
            if(StringUtils.isNotBlank(json)){
                Map map1=JsonUtils.readValue(json);
                if(StringUtils.equals("success", map1.get("type")+"")){

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                    WebsocketApproveConstant.refrashDealData(receiver);

                    return OperationResult.buildSuccessResult(map1.get("data"));
                }
                return OperationResult.buildFailureResult(map1.get("message")+"", map1.get("data"));
            }else{
                return OperationResult.buildFailureResult("参数不能为空");
            }
        } catch (Exception e) {
            if (logEnable) {
                logService.saveModuleLog(logCode, title, "", UuidUtils.UUID());
            }
            LOG.error("跳转失败", e);
            return OperationResult.buildFailureResult("跳转失败");
        }
    }

    @ApiOperation(value = "流程传阅", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserIds", value = "传阅人id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserNames", value = "传阅人姓名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/createReadTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult createReadTask(String taskId, String targetUserIds, String targetUserNames,
                                          String module, String processInstanceId,
                                          String permissionCode, HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String menuType = request.getParameter("menuType");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        bodyParams.put("targetUserIds", targetUserIds);
        bodyParams.put("targetUserNames", targetUserNames);
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));

        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        permissionCode = module + ":" + permissionCode + ":cy";
        try {
            String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
            this.pendingTaskService.createReadTaskSync(params, bodyDataParams, user.getJwtToken(), menuType,"", taskId );

            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null);
            }

           /* ArrayList<String> receiver=new ArrayList<>();
            String[] split = targetUserIds.split(",");
            for (int i = 0; i < split.length; i++) {
                receiver.add(split[i]);
            }
            receiver.add(user.getUserId());

            //ws刷新 add by V4.4 2023-7-18 14:31:14
            WebsocketApproveConstant.refrashDealData(receiver);*/

            return OperationResult.buildSuccessResult();
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("传阅失败", e);
            return OperationResult.buildFailureResult("传阅失败");
        }
    }

    @ApiOperation(value = "挂起流程", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "提醒对象：1-指定环节办理人  2-所有环节办理人", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "cancelReasonText", value = "取消原因", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/suspendProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult suspendProcess(String processInstanceId, String module, String permissionCode, HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderObject = request.getParameter("reminderObject");
        String designActivity = request.getParameter("designActivity");
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String cancelReasonText = request.getParameter("cancelReasonText");
        String dataId = request.getParameter("dataId");
        String formId = request.getParameter("formId");
        String sapJson = StringUtils.null2String(request.getParameter("sapJson"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("processInstanceId", processInstanceId);
        params.put("processInstanceIds", processInstanceId);
        permissionCode = module + ":" + permissionCode + ":qx";
        pendingTaskService.releaseProcessForm(processInstanceId, user.getJwtToken(), user.getUserId(), user.getCorpId(),
                "0");

        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);
        String doingTaskIds = pendingTaskService.getDoingTaskIds(processInstanceId);
        List<Map> mapList = new ArrayList<>();
        ArrayList<String> receiver=new ArrayList<>();
        if (null != list && list.size() > 0) {
            for (Map maps : list) {
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("dataId", dataId);
                m.put("formId", formId);
                m.put("module", module);
                m.put("processTitle", title);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "取消");
                m.put("messageContent", cancelReasonText);
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程取消提醒");
                mapList.add(m);
                receiver.add(maps.get("userId") + "");
            }
        }
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("sapJson", sapJson);
        String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
        String json = approveApiClient.suspendProcess(params,bodyDataParams,user.getJwtToken());
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
                pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), doingTaskIds, user.getJwtToken(), module);
                pendingTaskService.updateFormSqlByProInsId(processInstanceId, "4");
                pendingTaskService.updateCancelReasonByProInsId(processInstanceId, cancelReasonText);

                pendingTaskService.sendReminder(mapList, user.getJwtToken());

                receiver.add(user.getUserId());

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("操作失败", e);
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "自由流部署 自由流启动时修改流程定义并部署", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "defineId", value = "流程编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "bpmn", value = "流程设置xml数据", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/deploy", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult deploy(String defineId, String bpmn) {
        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("bpmn", bpmn);
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("defineId", defineId);
        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            String json = approveApiClient.deploy( params,bodyDataParams,user.getJwtToken());
            return pendingTaskService.stringToOperation(json);
        } catch (JsonProcessingException e) {
            LOG.error("操作失败", e);
            return OperationResult.buildFailureResult("操作失败");
        }
    }

    @ApiOperation(value = "流程作废", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "提醒对象：1-指定环节办理人  2-所有环节办理人", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processData", value = "流程数据", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/cancelProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult cancelProcess(String processInstanceId, String taskId, String module,
                                         String permissionCode, HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderObject = request.getParameter("reminderObject");
        String designActivity = request.getParameter("designActivity");
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String processData = request.getParameter("processData");
        String dataId = request.getParameter("dataId");
        String formId = request.getParameter("formId");
        String sapJson = StringUtils.null2String(request.getParameter("sapJson"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("processInstanceId", processInstanceId);
        params.put("processInstanceIds", processInstanceId);
        params.put("processDataClear", processData);
        if (StringUtils.isNotBlank(taskId)) {
            params.put("taskId", taskId);
        }
        permissionCode = module + ":" + permissionCode + ":zf";

        String type = "0";
        if (StringUtils.equals("2", processData)) {
            type = "1";
        }

        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);

        if("1".equals(type)){
            Map<String, String> param = new HashMap<String, String>();
            param.put("userId", user.getUserId());
            param.put("corpId", user.getCorpId());
            param.put("taskId", taskId);
            param.put("buttonCode", "BASE_INVALID");
            param.put("processInstanceId", processInstanceId);
            String json = this.approveApiClient.judgeButtonAuth(param, user.getJwtToken());
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                //注：type=1时 此方法也会删除任务
                pendingTaskService.releaseProcessForm(processInstanceId, user.getJwtToken(), user.getUserId(), user.getCorpId(), type);
            }else{
                return OperationResult.buildFailureResult(StringUtils.null2String(map.get("message")));
            }
        }

        if("1".equals(type)){ // 数据清除
            return OperationResult.buildSuccessResult("作废成功");
        }

        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        List<Map> mapList = new ArrayList<>();
        ArrayList<String> receiver=new ArrayList<>();
        if (null != list && list.size() > 0) {
            for (Map maps : list) {
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("dataId", dataId);
                m.put("formId", formId);
                m.put("module", module);
                m.put("processTitle", title);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "作废");
                m.put("messageContent", "该流程已作废");
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程作废提醒");
                mapList.add(m);
                receiver.add(maps.get("userId") + "");
            }
        }
        params.put("groupId", orgId);
        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        bodyParams.put("sapJson", sapJson);
        String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
        String json = approveApiClient.cancelProcess( params,bodyDataParams,user.getJwtToken());
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
                //清除消息数据
                if (StringUtils.equals("1", processData)) {
                    String taskIds = pendingTaskService.getAllTaskIds(user.getUserId(), user.getCorpId(), processInstanceId, user.getJwtToken());
                    Map<String, String> ms = new HashMap<String, String>();
                    ms.put("taskId", taskIds);
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
                }
                pendingTaskService.updateFormSqlByProInsId(processInstanceId, "3");
                if (StringUtils.equals("2", processData)){
                    for(Map m :mapList){
                        //发消息
                        m.put("taskIds", m.get("taskId"));
                        m.put("userIds", m.get("userId"));
                        m.put("taskNames", m.get("typeName"));
                        m.put("userNames", m.get("userId"));
                        m.put("categoryCode", "");
                        m.put("officeFullPath", GlobalConstant.getFlexOfficeFullPath(request));
                        pendingTaskService.sendNoticeSleep(m, request, user);
                    }
                }else{
                    pendingTaskService.sendReminder(mapList, user.getJwtToken());
                }
                receiver.add(user.getUserId());
                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("操作失败", e);
        }

        return pendingTaskService.stringToOperation(json);
    }

    @RequestMapping(value = "/hideProcessInstance", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ids", value = "id串", required = true, paramType = "query", dataType = "String"),
    })
    @ResponseBody
    public OperationResult hideProcessInstance(HttpServletRequest request, String module, @RequestParam("ids") String... ids){
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        boolean res = true;
        //--------------- 平行越权  2022年6月22日18:11:12
        String secdatacodes = StringUtils.null2String(request.getParameter("secdatacodes"));
        String[] secdatacodeArray = secdatacodes.split(",");
        for(int i=0;i<secdatacodeArray.length;i++){
            String secdatacode = secdatacodeArray[i];
            if(!ApproveSecUtils.verifyData("processInstanceId"+ids[i],secdatacodeArray[i])){
                res = false;
                break ;
            }
        }
        if(!res){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //--------------- 平行越权  2022年6月22日18:11:12

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> userParams = new HashMap<String, String>();
        userParams.put("userId", user.getUserId());
        userParams.put("corpId", user.getCorpId());
        userParams.put("module", module);
        userParams.put("processInstanceId", StringUtils.join(ids, ","));

        String json = approveApiClient.hideProcessInstance( userParams,user.getJwtToken());

        //ws刷新 add by V4.4 2023-7-18 14:31:14
       // WebsocketApproveConstant.refrashDealData(null);

        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程删除", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "流程ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/deleteProcessInstance", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult deleteProcessInstance(HttpServletRequest request, String module, String permissionCode,
                                                 @RequestParam("ids") String... ids) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> userParams = new HashMap<String, String>();
        userParams.put("userId", user.getUserId());
        userParams.put("corpId", user.getCorpId());
        userParams.put("module", module);
        userParams.put("processInstanceIds", StringUtils.join(ids, ","));
        userParams.put("type", "1");

        String json = "";
        permissionCode = module + ":" + permissionCode + ":04";
        boolean flage = logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken());
        List<Map<String, String>> operateDataList = new ArrayList<Map<String, String>>();
        if (null != ids && ids.length > 0) {
            List<Map> titleList = new ArrayList<Map>();
            if (flage) {
                List idsList = Arrays.asList(ids);
                titleList = pendingTaskService.getTitleByProInsIds(idsList);
            }
            for (int i = 0; i < ids.length; i++) {
                userParams.put("processInstanceId", ids[i]);
                String taskIds = pendingTaskService.getAllTaskIds(user.getUserId(), user.getCorpId(), ids[i], user.getJwtToken());
                List<Map> userTaskList= pendingTaskService.getDoingUserTaskList(Arrays.asList(taskIds.split(",")));
                json = approveApiClient.deleteProcessInstance( userParams,user.getJwtToken());
                Map<String, String> operateDataMap = new HashMap<>();
                operateDataMap.put("operateDetails", "");
                ObjectMapper mapper = new ObjectMapper();
                try {
                    Map<String, Object> map = mapper.readValue(json, Map.class);
                    if ("success".equals(map.get("type").toString())) {
                        pendingTaskService.releaseProcessFormNowSleep(ids[i], user.getJwtToken(), user.getUserId(),
                                user.getCorpId());
                        if (flage) {
                            operateDataMap.put("requestId", null);
                            if (null != titleList && titleList.size() > 0) {
                                for (Map maps : titleList) {
                                    if (StringUtils.equals(ids[i], maps.get("proId") + "")) {
                                        operateDataMap.put("operateData", maps.get("title") + "");
                                        break;
                                    }
                                }
                            }
                        }
                        List<String> receiveUserIds = new ArrayList<>();
                        for(Map m : userTaskList){
                            receiveUserIds.add(StringUtils.null2String(m.get("userId")));
                            String uid=m.get("userId")+"";
                            String tid=m.get("taskId")+"";
                            pendingTaskService.clearMsgDone( ids[i], module, tid,
                                    user.getCorpId(),uid,user.getJwtToken());
                        }
                        receiveUserIds.add(user.getUserId());

                        //ws刷新 add by V4.4 2023-7-18 14:31:14
                        WebsocketApproveConstant.refrashDealData(receiveUserIds);

                        pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), taskIds, user.getJwtToken(), module);
                    } else {
                        if (flage) {
                            if (null != titleList && titleList.size() > 0) {
                                for (Map maps : titleList) {
                                    if (StringUtils.equals(ids[i], maps.get("proId") + "")) {
                                        operateDataMap.put("operateData", maps.get("title") + "");
                                        break;
                                    }
                                }
                            }
                            operateDataMap.put("requestId", UuidUtils.UUID());
                        }
                    }
                    operateDataList.add(operateDataMap);
                } catch (Exception e) {
                    if (flage) {
                        operateDataMap.put("requestId", UuidUtils.UUID());
                        if (null != titleList && titleList.size() > 0) {
                            for (Map maps : titleList) {
                                if (StringUtils.equals(ids[i], maps.get("proId") + "")) {
                                    operateDataMap.put("operateData", maps.get("title") + "");
                                    break;
                                }
                            }
                        }
                        operateDataList.add(operateDataMap);
                    }
                    LOG.error("删除失败", e);
                }

            }
        }
        if (flage) {
            logService.batchSaveModuleLog(permissionCode, operateDataList, request);
        }
        return pendingTaskService.stringToOperation(json.replace("成功", "删除成功"));
    }

    @ApiOperation(value = "待阅任务详情", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "阅件id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getReadTaskInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getReadTaskInfo(HttpServletRequest request,String taskId) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if( !ApproveSecUtils.verifyData("id"+taskId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String module = StringUtils.null2String(request.getParameter("module"));

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("userId", user.getUserId());
        hm.put("corpId", user.getCorpId());
        hm.put("taskId", taskId);
        String json = approveApiClient.getReadTaskInfo( hm,user.getJwtToken());
        Map map = JsonUtils.readValue(json);
        if (StringUtils.equals("success", map.get("type") + "")) {
            Map m = (Map) map.get("data");
            m.put("taskId", pendingTaskService.getTaskIdByReadId(taskId));

            if (StringUtils.isNotBlank(module)) {
                String reminderAction = this.pendingTaskService.getReminderActionByCode(module);
                m.put("reminderAction", reminderAction);
            }

            return OperationResult.buildSuccessResult(m);
        }
        return OperationResult.buildFailureResult(map.get("message") + "", map.get("data"));
    }

    @ApiOperation(value = "获取组织下的用户", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgIds", value = "组织ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUsersByOrgIds", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUsersByOrgIds(String orgIds) {
        List<Map> list = pendingTaskService.getUsersByOrgIds(orgIds);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "根据群组id获取用户", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupIds", value = "群组ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUserIdsByGrpId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUserIdsByGrpId(String groupIds) {
        List list =pendingTaskService.getUserIdsByGrpId(groupIds);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "根据岗位id获取用户", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationIds", value = "岗位ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUserIdsByStationId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUserIdsByStationId(String stationIds) {
        List list =pendingTaskService.getUserIdsByStationId(stationIds);
        return OperationResult.buildSuccessResult(list);
    }


    @ApiOperation(value = "根据个人群组id获取用户", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "personalgrpIds", value = "群组ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUserIdsByPersonalgrpId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUserIdsByPersonalgrpId(String personalgrpIds) {
        List list =pendingTaskService.getUserIdsByPersonalgrpId(personalgrpIds);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "批量提交流程", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskIds", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceIds", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formIds", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "participantMode", value = "办理方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealActionName", value = "操作按钮名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "selectedActivity", value = "所选节点", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgency", value = "紧急", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentId", value = "批示意见id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentFileId", value = "批示意见附件id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/completeTaskBatch", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult completeTaskBatch(String taskIds, String module, String processInstanceIds, String permissionCode,
                                             String formIds, String participantMode, String dealActionName, String selectedActivity,
                                             String urgency, String comment, HttpServletRequest request) {
        LOG.debug("completeTaskBatch    批量提交流程...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        boolean res = true;
        //--------------- 平行越权  2022年6月22日18:11:12
        String secdatacodes = StringUtils.null2String(request.getParameter("secdatacodes"));
        String[] secdatacodeArray = secdatacodes.split(",");
        String[] taskIdArray = taskIds.split(",");
        String[] processInstanceIdArray = processInstanceIds.split(",");
        for(int i=0;i<secdatacodeArray.length;i++){
            List<String> list = new ArrayList<>();
            list.add("processInstanceId"+processInstanceIdArray[i]);
            list.add("id"+taskIdArray[i]);//参数加密时用的是id  故此处不是taskId
            if(!ApproveSecUtils.verifyData(list,secdatacodeArray[i])){
                res = false;
                break ;
            }
        }
        if(!res){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //--------------- 平行越权  2022年6月22日18:11:12

        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String commentId = request.getParameter("commentId");
        String commentFileId = request.getParameter("commentFileId");
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (comment != null) {
            bodyParams.put("comment", comment);
            if (StringUtils.isNotBlank(commentId) && !"null".equals(commentId) && !"undefined".equals(commentId)) {
                bodyParams.put("commentId", commentId);
            }
        }
        if (commentFileId != null) {
            bodyParams.put("commentFileId", commentFileId);
        }
        bodyParams.put("dealActionName", dealActionName);
        String permissionCodes = module + ":" + permissionCode + ":tg";
        if (StringUtils.equals("draft", permissionCode)) {
            permissionCodes = module + ":" + permissionCode + ":tj";
        }

        if (StringUtils.isNotBlank(selectedActivity)) {
            bodyParams.put("selectedActivity", selectedActivity);
        }

        if (StringUtils.isNotBlank(urgency) && !"null".equals(urgency) && !"undefined".equals(urgency)) {
            bodyParams.put("urgency", urgency);
        }
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());

        params.put("groupId", orgId);
        params.put("taskIds", taskIds);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);

            LOG.debug("params:"+mapper.writeValueAsString(params));
            LOG.debug("bodyDataParams:"+bodyDataParams);

            String json = approveApiClient.completeTaskBatch( params,bodyDataParams,user.getJwtToken());
            LOG.debug("json:"+json);
            List<Map> mapList = pendingTaskService.getTitleByProInsIds(Arrays.asList(processInstanceIds.split(",")));
            Map<String, Object> map = mapper.readValue(json, Map.class);
            List<Map<String, String>> operateDataList = new ArrayList<Map<String, String>>();
            if ("success".equals(map.get("type").toString())) {
                Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
                List<Map<String, String>> successList = (List<Map<String, String>>) dataMap.get("successList");
                String pids[] = processInstanceIds.split(",");
                String tids[] = taskIds.split(",");
                String fids[] = formIds.split(",");
                List<String> newProList = new ArrayList<String>();
                if (null != successList && successList.size() > 0) {
                    for (Map<String, String> sucMap : successList) {
                        for (int j = 0; j < tids.length; j++) {
                            if (StringUtils.equals(sucMap.get("taskId"), tids[j])) {
                                newProList.add(pids[j]);
                                Map<String, String> ms = new HashMap<String, String>();
                                for (Map ml : mapList) {
                                    if (StringUtils.equals(pids[j], ml.get("proId").toString())) {
                                        ms.put("title", ml.get("title") + "");
                                        break;
                                    }
                                }
                                ms.put("showType", "0");
                                pendingTaskService.takeMsgDoneSleep(module, pids[j], sucMap, user.getUserId(), user.getCorpId(), user.getJwtToken());
                                String isEnd = "0";
                                String status = sucMap.get("status");
                                if ("2".equals(status)) {
                                    isEnd = "1";
                                }
                                boolean isAdd = false;
                                if (StringUtils.equals("draft", permissionCode)) {
                                    isAdd = true;
                                }
                                pendingTaskService.insertUpdateFormSql(isEnd, isAdd, fids[j], sucMap.get("dataId"),
                                        sucMap.get("processInstanceId"));
                            }
                        }
                    }
                }
                if (logService.checkOptLog(user.getCorpId(), permissionCodes, user.getJwtToken())) {
                    if (null != newProList && newProList.size() > 0) {
                        for (Map ml : mapList) {
                            Map<String, String> operateDataMap = new HashMap<>();
                            operateDataMap.put("operateDetails", "");
                            operateDataMap.put("operateData", ml.get("title") + "");
                            if (newProList.contains(ml.get("proId"))) {
                                operateDataMap.put("requestId", null);
                            } else {
                                operateDataMap.put("requestId", UuidUtils.UUID());
                            }
                            operateDataList.add(operateDataMap);
                        }
                    } else {
                        for (Map ml : mapList) {
                            Map<String, String> operateDataMap = new HashMap<>();
                            operateDataMap.put("operateDetails", "");
                            operateDataMap.put("operateData", ml.get("title") + "");
                            operateDataMap.put("requestId", null);
                            operateDataList.add(operateDataMap);
                        }
                    }
                    logService.batchSaveModuleLog(permissionCodes, operateDataList, request);
                }
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCodes, user.getJwtToken())) {
                    for (Map ml : mapList) {
                        Map<String, String> operateDataMap = new HashMap<>();
                        operateDataMap.put("operateDetails", "");
                        operateDataMap.put("operateData", ml.get("title") + "");
                        operateDataMap.put("requestId", UuidUtils.UUID());
                        operateDataList.add(operateDataMap);
                    }
                    logService.batchSaveModuleLog(permissionCodes, operateDataList, request);
                }
            }

           /* ArrayList<String> receiver = new ArrayList<>();
            receiver.add(user.getUserId());
            if (StringUtils.isNotBlank(selectedActivity)) {
                List<Map<String, String>> lm = JsonUtils.readListValue(selectedActivity);
                if(lm!=null && lm.size()>0){
                    for(Map<String, String> p:lm){
                        String participants = StringUtils.null2String(p.get("participants"));
                        receiver.addAll(Arrays.asList(participants.split(",")));
                    }
                }
            }*/

            if(StringUtils.isNotBlank(JSON.toJSONString(map))){
                Map map1=JsonUtils.readValue(JSON.toJSONString(map));
                if(StringUtils.equals("success", map1.get("type")+"")){

                    //ws刷新 add by V4.4 2023-7-18 14:31:14
                   // WebsocketApproveConstant.refrashDealData(receiver);

                    return OperationResult.buildSuccessResult(map1.get("data"));
                }
                return OperationResult.buildFailureResult(map1.get("message")+"", map1.get("data"));
            }else{
                return OperationResult.buildFailureResult("参数不能为空");
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                List<Map<String, String>> operateDataList = new ArrayList<Map<String, String>>();
                List<Map> mapList = pendingTaskService.getTitleByProInsIds(Arrays.asList(processInstanceIds.split(",")));
                for (Map ml : mapList) {
                    Map<String, String> operateDataMap = new HashMap<>();
                    operateDataMap.put("operateDetails", "");
                    operateDataMap.put("operateData", ml.get("title") + "");
                    operateDataMap.put("requestId", UuidUtils.UUID());
                    operateDataList.add(operateDataMap);
                }
                logService.batchSaveModuleLog(permissionCodes, operateDataList, request);
            }
            LOG.error("提交失败", e);
            return OperationResult.buildFailureResult("提交失败");
        }
    }

    @ApiOperation(value = "批量阅件", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskBatchIds", value = "任务ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "batchProcessInstanceIds", value = "流程实例ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/readCompleteTaskBatch", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult readCompleteTaskBatch(HttpServletRequest request,String taskBatchIds, String module, String permissionCode,
                                                 String batchProcessInstanceIds) {
        LOG.debug("###  批量阅件  readCompleteTaskBatch...");
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);


        boolean res = true;
        //--------------- 平行越权  2022年6月22日18:11:12
        String secdatacodes = StringUtils.null2String(request.getParameter("secdatacodes"));
        String[] secdatacodeArray = secdatacodes.split(",");
        String[] processInstanceIdArray = batchProcessInstanceIds.split(",");
        for(int i=0;i<secdatacodeArray.length;i++){
            if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceIdArray[i],secdatacodeArray[i])){
                res = false;
                break ;
            }
        }
        if(!res){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //--------------- 平行越权  2022年6月22日18:11:12


        ObjectMapper mapper = new ObjectMapper();
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskIds", taskBatchIds);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        permissionCode = module + ":" + permissionCode + ":yy";
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        try {
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            String json = approveApiClient.readCompleteTaskBatch( params,bodyDataParams,user.getJwtToken());
            Map<String, Object> map = mapper.readValue(json, Map.class);
            if ("success".equals(map.get("type").toString())) {
                // 完成消息
                pendingTaskService.updateReadUmcMessageStatus(taskBatchIds);
                pendingTaskService.takeReadMsgDone(module, taskBatchIds, user.getCorpId(), user.getUserId(),
                        user.getJwtToken());

                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    List<Map> listMap = pendingTaskService.getTitleByProInsIds(Arrays.asList(batchProcessInstanceIds.split(",")));
                    if (null != listMap && listMap.size() > 0) {
                        for (int i = 0; i < listMap.size(); i++) {
                            logService.saveModuleLog(permissionCode, listMap.get(i).get("title") + "", null);
                        }
                    }
                }

                //ws刷新 add by V4.4 2023-7-18 14:31:14
               // WebsocketApproveConstant.refrashDealData(null);

            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    List<Map> listMap = pendingTaskService.getTitleByProInsIds(Arrays.asList(batchProcessInstanceIds.split(",")));
                    if (null != listMap && listMap.size() > 0) {
                        for (int i = 0; i < listMap.size(); i++) {
                            logService.saveModuleLog(permissionCode, listMap.get(i).get("title") + "", null,
                                    UuidUtils.UUID());
                        }
                    }
                }
            }
            return pendingTaskService.stringToOperation(json);
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                List<Map> listMap = pendingTaskService.getTitleByProInsIds(Arrays.asList(batchProcessInstanceIds.split(",")));
                if (null != listMap && listMap.size() > 0) {
                    for (int i = 0; i < listMap.size(); i++) {
                        logService.saveModuleLog(permissionCode, listMap.get(i).get("title") + "", null,
                                UuidUtils.UUID());
                    }
                }
            }
            LOG.error("批量阅件失败", e);
            return OperationResult.buildFailureResult("批量阅件失败");
        }
    }

    @ApiOperation(value = "撤回发起人", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskIds", value = "任务ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userIds", value = "用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskNames", value = "任务名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userNames", value = "用户名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryCode", value = "流程分类编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/recallmyprocess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult recallmyprocess(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = request.getParameter("processInstanceId");

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String module = request.getParameter("module");
        String permissionCode = request.getParameter("permissionCode");
        String taskIds = request.getParameter("taskIds");
        String title = request.getParameter("processTitle");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("userId", user.getUserId());
        hm.put("corpId", user.getCorpId());
        hm.put("processInstanceId", processInstanceId);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        hm.put("groupId", orgId);
        hm.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        hm.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        permissionCode = module + ":" + permissionCode + ":cx";
        List<Map> tskUserList = new ArrayList<Map>();
        taskIds=pendingTaskService.getDoingTaskIds(processInstanceId);
        String tids[] = taskIds.split(",");

        List<String> receiver = new ArrayList<>();
        receiver.add(user.getUserId());

        for(String tid : tids){
            Map<String, String> ms = new HashMap<String, String>();
            ms.put("taskId", tid);
            String uid = pendingTaskService.getDoingUserIds(tid);
            ms.put("userId", uid);
            tskUserList.add(ms);

            receiver.add(uid);
        }
        String json = "";
        try {
            json = approveApiClient.recallmyprocess( hm,user.getJwtToken());
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
                for(Map m1 : tskUserList){
                    pendingTaskService.clearMsgDone( processInstanceId, module, m1.get("taskId")+"",
                            user.getCorpId(),m1.get("userId")+"", user.getJwtToken());
                }
                // 完成消息
                pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), taskIds, user.getJwtToken(), module);
                //发消息
                Map<String, String> m = new HashMap<String, String>();
                m.put("typeName", "撤回");
                m.put("messageContent", "该流程已撤回");
                String userIds = request.getParameter("userIds");
                String taskNames = request.getParameter("taskNames");
                String userNames = request.getParameter("userNames");
                String reminderContent = request.getParameter("reminderContent");
                String reminders = request.getParameter("reminders");
                String categoryCode = request.getParameter("categoryCode");
                String formId = request.getParameter("formId");
                String dataId = request.getParameter("dataId");
                m.put("taskIds", taskIds);
                m.put("userIds", userIds);
                m.put("taskNames", taskNames);
                m.put("userNames", userNames);
                m.put("reminderContent", reminderContent);
                m.put("module", module);
                m.put("reminders", reminders);
                m.put("processInstanceId", processInstanceId);
                m.put("categoryCode", categoryCode);
                m.put("formId", formId);
                m.put("dataId", dataId);
                m.put("processTitle", title);
                m.put("categoryCode", categoryCode);
                m.put("orgId", orgId);
                m.put("taskType", "5");
                m.put("msgTitle", "流程撤回提醒");
                m.put("officeFullPath", GlobalConstant.getFlexOfficeFullPath(request));
                pendingTaskService.sendNoticeSleep(m, request, user);

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                /** 清理办理人正文锁信息 **/
                bpmProcessTextlockService.delTextlock(user.getUserId(),processInstanceId);

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程撤回失败", e);
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取钉钉用户", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doingUserIds", value = "用户ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getDingUsers", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult getDingUsers(String doingUserIds) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> returnParam = new HashMap<String, Object>();
        List<String> userMap = new ArrayList<String>();
        if (StringUtils.isNotBlank(doingUserIds)) {
            userMap = userApiService.getUserIdBySysOrThird(doingUserIds, "1", "DD", user.getCorpId(),
                    user.getJwtToken());
            returnParam.put("doingUser", userMap);
        }
        GlobalConstant globalConstant = new GlobalConstant();// 读取配置文件class
        String dingdingType = globalConstant.getConfig("dingding.type");
        if (dingdingType.equals("isv")) { // 企业
            String suiteKey = globalConstant.getConfig("dingisv.module.mobileportal.suiteKey");
            String appId = globalConstant.getConfig("dingisv.module.mobileportal.appid");
            returnParam.put("suiteKey", suiteKey);
            returnParam.put("appId", appId);
            returnParam.put("corpId", user.getCorpId());
            returnParam.put("dingType", "isv");
        } else {
            returnParam.put("dingType", "corp");
        }

        return pendingTaskService.stringToOperation(JSON.toJSONString(returnParam));
    }

    @ApiOperation(value = "获取用户设置的常用语", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/getPersonalPhrase", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getPersonalPhrase() {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("userId", user.getUserId());
        hm.put("corpId", user.getCorpId());
        String json = approveApiClient.getPersonalPhrase( hm,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "保存用户设置的常用语", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "comment", value = "批示意见", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/savePersonalPhrase", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult savePersonalPhrase(String comment) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("userId", user.getUserId());
        hm.put("content", comment);
        String json = approveApiClient.savePersonalPhrase( hm,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程催办", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskUserIds", value = "任务用户ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgeTitle", value = "催办标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "urgeContent", value = "催办内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/urgeProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult urgeProcess(String taskUserIds, String urgeTitle, String urgeContent, String processInstanceId,
                                       String module, String reminders, String permissionCode, HttpServletRequest request)
            throws JsonProcessingException {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String receiveUserIds = "";
        String taskIds = "";
        String[] taskUserIdArry = taskUserIds.split(",");
        for(String idStr : taskUserIdArry){
            String[] ids = idStr.split(";");

            receiveUserIds += ids[1]+",";
            taskIds += ids[0]+",";
        }

        WebUser user = WebUtils.getCurrentUser();
        UrgeMsgDto urgeMsgDto = new UrgeMsgDto();
        urgeMsgDto.setModule(module);
        urgeMsgDto.setUrgeContent(urgeContent);
        urgeMsgDto.setCorpId(user.getCorpId());
        urgeMsgDto.setProcessInstanceId(processInstanceId);
        urgeMsgDto.setPermissionCode(permissionCode);
        urgeMsgDto.setReceiveUserIds(receiveUserIds);
        urgeMsgDto.setTaskIds(taskIds);
        urgeMsgDto.setReminders(reminders);
        urgeMsgDto.setUserId(user.getUserId());
        urgeMsgDto.setUserName(user.getCnName());
        urgeMsgDto.setToken(user.getJwtToken());
        urgeMsgDto.setUrgeTitle(urgeTitle);
        this.approveSendMessageApiService.sendUrgeMsg(urgeMsgDto);


        ArrayList<String> receiver=new ArrayList<>();
        String[] split = taskUserIds.split(",");
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i].split(";")[1]);
        }
        //ws刷新 add by V4.4 2023-7-18 14:31:14
        WebsocketApproveConstant.refrashDealData(receiver);

        return OperationResult.buildSuccessResult();
    }

    @ApiOperation(value = "根据流程定义code获取分类信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "流程code", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getCateByProCode", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getCateByProCode(String code) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("code", code);
        hm.put("corpId", user.getCorpId());
        String json = approveApiClient.getCateByProCode( hm,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取打印模板", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formType", value = "表单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgShowType", value = "批示意见落款 组织类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getPrintTemplateInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getPrintTemplateInfo(HttpServletRequest request,String formId, String dataId, String formType,
                                                String processInstanceId, String permissionCode, String module,String orgShowType) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();

        //公文查询记录操作日志
        String logModule = StringUtils.null2String(request.getParameter("logModule"));
        String logCode = module + ":" + permissionCode + ":tz";

        /**
         * 公文查询 操作日志记录 特殊处理
         *  发文查询：
         *      sendFile:flowQuery:js   结束
         *      sendFile:flowQuery:dy   打印
         *      sendFile:flowQuery:tz   跳转
         *  收文查询：
         *       receiveFile:flowQuery:js   结束
         *       receiveFile:flowQuery:dy   打印
         *       receiveFile:flowQuery:tz   跳转
         *  签报查询：
         *       signReport:flowQuery:js   结束
         *       signReport:flowQuery:dy   打印
         *       signReport:flowQuery:tz   跳转
         *
         */
        if("goa_document".equals(module)){
            //流程查询
            if("flowQuery".equals(permissionCode) && StringUtils.isNotBlank(logModule)){
                logCode = logModule + ":" + permissionCode + ":tz";
            }
        }

        if (logService.checkOptLog(user.getCorpId(), logCode, user.getJwtToken())) {
            String title = pendingTaskService.getTitleByProInsId(processInstanceId);
            logService.saveModuleLog(logCode, title, null);
        }
        if (StringUtils.equals("4", formType)) {
            return null;
        }
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);
        params.put("corpId", corpId);
        params.put("formId", formId);
        params.put("dataId", dataId);
        params.put("formType", formType);
        String json = approveApiClient.getPrintTemplateInfo( params,user.getJwtToken());
        LOG.debug("getPrintTemplateInfo :"+json);
        Map<String, Object> map = JsonUtils.readValue(json);
        if ("success".equals(map.get("type").toString())) {
            Map<String, Object> result = (Map<String, Object>) map.get("data");
            result.put("userId", user.getUserId());
            result.put("corpId", user.getCorpId());
            result.put("userName", user.getCnName());
            List<Map<String, Object>> bookmarkInfo = (List<Map<String, Object>>)result.get("bookmarkInfo");
            if(bookmarkInfo != null && !bookmarkInfo.isEmpty()){
                boolean isDocument = "goa_document".equals(module);
                String value = "", fieldCode = "", receiveOrgId = "", jgdzId = "", sendFileNo = "", jeremylevinComments = "";
                Map<String, Object> documentMap = new HashMap<String, Object>();
                if(isDocument){
                    for(Map<String, Object> m : bookmarkInfo){
                        fieldCode = StringUtils.null2String(m.get("fieldCode"));
                        value = StringUtils.null2String(m.get("value"));
                        if("goa_doc_receivefile_receive_unit".equals(fieldCode))
                            receiveOrgId = value;
                        else if("goa_doc_sendfile_jgdz_id".equals(fieldCode))
                            jgdzId = value;
                        else if("goa_doc_sendfile_issued_number".equals(fieldCode))
                            sendFileNo = value;
                        else if("goa_doc_receivefile_jeremylevin_comments".equals(fieldCode))
                            jeremylevinComments = value;

                    }
                    documentMap = getDocumentFieldInfo(receiveOrgId, jgdzId, sendFileNo, jeremylevinComments, dataId, token);
                }
                Map<String, List<Map<String, Object>>> commentListMap = getComment(processInstanceId, userId, corpId, token);
                LOG.debug("获取批示意见内容-------->bookmarkInfo:"+JSON.toJSONString(bookmarkInfo));

                LOG.debug("获取批示意见内容-------->commentListMap:"+JSON.toJSONString(commentListMap));
                for(Map<String, Object> m : bookmarkInfo){
                    String showCode = StringUtils.null2String(m.get("showCode"));
                    fieldCode = StringUtils.null2String(m.get("fieldCode"));
                    if(isDocument){
                        if("goa_doc_receivefile_receive_unit".equals(fieldCode)){
                            m.put("value", StringUtils.null2String(documentMap.get("receiveOrgName")));
                        } else if("goa_doc_sendfile_jgdz_id".equals(fieldCode)) {
                            m.put("value", StringUtils.null2String(documentMap.get("sendFileNumName")));
                        } else if("goa_doc_sendfile_issued_number".equals(fieldCode)){
                            m.put("value", StringUtils.null2String(documentMap.get("sendFileNo")));
                        } else if("goa_doc_receivefile_jeremylevin_comments".equals(fieldCode)){
                            m.put("value", StringUtils.null2String(documentMap.get("jeremylevinComments")));
                        }
                    }
                    if("comment".equals(showCode)){ // 批示意见字段

                        /** 套打 默认意见
                         *  条件： 数据表需要新增意见字段，defaultComment 表单勾选之，套打模板选择标签
                         * **/
                        if(fieldCode.indexOf("defaultComment")>-1){ // 批示意见字段
                            List<Map> commentList = getFullMessage(commentListMap.get("default"),orgShowType,token);
                            m.put("value", JSON.toJSONString(commentList));
                        }else{
                            m.put("value", JSON.toJSONString(getFullMessage(commentListMap.get(fieldCode),orgShowType,token)));
                        }
                    }
                }
            }
            return OperationResult.buildSuccessResult(result);
        }
        return null;
    }

    /**
     * 获取批示意见内容
     */
    public List<Map> getFullMessage(List<Map<String, Object>> list,String orgShowType,String token){
        List<Map> commentList = new ArrayList<>();
        if(list != null && !list.isEmpty()){
            for(Map<String, Object> m : list){
                Map<String, Object> commentmap = new HashMap<>();

                String userId = StringUtils.null2String(m.get("userId"));
                String commentType = StringUtils.null2String(m.get("type"));//evosign-h5手写意见  text-文本意见
                commentmap.put("type","comment");

                String fullMessage = StringUtils.null2String(m.get("fullMessage"));
                if("evosign".equals(commentType) && fullMessage.length()>0){
                    commentmap.put("content",  "");
                    String image = getImageUrlById(fullMessage, token);
                    commentmap.put("contentImage",  image);
                }else{
                    commentmap.put("content",  fullMessage);
                }

                String inscriptionShow = StringUtils.null2String(m.get("inscriptionShow"));
                if(StringUtils.isNotBlank(inscriptionShow)){
                    commentmap.put("inscriptionShow",inscriptionShow);
                    String[] iss = inscriptionShow.split(",");
                    StringBuffer dateStr = new StringBuffer("");
                    for(String is : iss){
                        switch (is){
                            case "userName":
                                commentmap.put("userName", m.get("userName"));
                                break;
                            case "org":
                                String orgId = StringUtils.null2String(m.get("orgId"));
                                Map<String, String> params = new HashMap<>();
                                params.put("type", StringUtils.null2String(m.get("orgShowtype")));
                                params.put("orgId", orgId);
                                String json = approveApiClient.getOrgNameInfo(params,token);
                                Map<String, Object> map = JsonUtils.readValue(json);
                                if ("success".equals(map.get("type").toString())) {
                                    String orgName = StringUtils.null2String(map.get("data"));
                                    dateStr.append(orgName+" " );
                                    commentmap.put("org", orgName);
                                }
                                break;
                            case "date":
                                dateStr.append(StringUtils.null2String(m.get("signtime")).split(" ")[0]+" " );
                                commentmap.put("dateinit", StringUtils.null2String(m.get("signtime")).split(" ")[0]);
                                break;
                            case "time":
                                dateStr.append(StringUtils.null2String(m.get("signtime")).split(" ")[1]+" " );
                                commentmap.put("time", StringUtils.null2String(m.get("signtime")).split(" ")[1]);
                                break;
                            case "activityName":
                                dateStr.append(StringUtils.null2String(m.get("activityName"))+"");
                                commentmap.put("activityName", StringUtils.null2String(m.get("activityName")));
                                break;
                            case "signImg":
                                String picId = pendingTaskService.getSignPicId(userId);
                                if(StringUtils.isNotBlank(picId)){
                                    String image = getImageUrlById(picId, token);
                                    commentmap.put("image",  image);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    commentmap.put("date",  dateStr.toString());
                }

                commentList.add(commentmap);
            }
        }

        LOG.debug("获取批示意见内容-------->commentList:"+JSON.toJSONString(commentList));
        return commentList;
    }

    //获取图片附件路径
    public String getImageUrlById(String picId, String token){
        String imageUrl = "";
        if(StringUtils.isNotBlank(picId)){
            Map param2 = new HashMap();
            param2.put("fids", picId);
            try {
                String scopeMap1 = approveApiClient.getAttachmentInfos(param2, token);
                Map<String,Object> map1 = JsonUtils.readValue(scopeMap1);
                if(StringUtils.equals("success", StringUtils.null2String(map1.get("type")))){
                    List<Map> attachment = (List<Map>)map1.get("data");
                    if(attachment!=null && attachment.size()>0){
                        imageUrl = StringUtils.null2String(attachment.get(0).get("imageUrl"));
                    }
                }
            }catch (Exception e){
                LOG.error(" getAttachmentInfos  获取失败",e);
            }
        }

        return imageUrl;
    }

    /**
     * 获取批示意见内容
     * @param list
     * @return
     */
    private String getFullMessage2(List<Map<String, Object>> list,String orgShowType,String token){
        String result = "";
        if(list != null && !list.isEmpty()){
            for(Map<String, Object> m : list){
                result += m.get("fullMessage") + "\n";
                String inscriptionShow = StringUtils.null2String(m.get("inscriptionShow"));
                if(StringUtils.isNotBlank(inscriptionShow)){
                    String[] iss = inscriptionShow.split(",");
                    for(String is : iss){
                        switch (is){
                            case "userName":
                                result += m.get("userName")+"  ";
                                break;
                            case "org":
                                String orgId = StringUtils.null2String(m.get("orgId"));
                                Map<String, String> params = new HashMap<>();
                                params.put("type", orgShowType);
                                params.put("orgId", orgId);
                                String json = approveApiClient.getOrgNameInfo( params,token);
                                Map<String, Object> map = JsonUtils.readValue(json);
                                if ("success".equals(map.get("type").toString())) {
                                    String orgName = StringUtils.null2String(map.get("data"));
                                    result += orgName+"  ";
                                }
                                break;
                            case "date":
                                result += StringUtils.null2String(m.get("signtime")).split(" ")[0] +"  ";
                                break;
                            case "time":
                                result += StringUtils.null2String(m.get("signtime")).split(" ")[1] +"  ";
                                break;
                            case "signImg":
                                break;
                            default:
                                break;
                        }
                    }
                }
                result += "\n";
            }
        }
        return result;
    }

    /** 仅测试使用 **/
    public String getCommentMessage(List<Map<String, Object>> list,String orgShowType,String token){
        List<Map<String,String>> messageList = new ArrayList<>();

        if(list != null && !list.isEmpty()){
            for(Map<String, Object> m : list){
                Map<String,String> map = new HashMap<>();

                String type = "comment";
                String content = StringUtils.null2String(m.get("fullMessage"));
                String userId = StringUtils.null2String(m.get("userId"));
                String userName = StringUtils.null2String(m.get("userName"));
                String signtime = StringUtils.null2String(m.get("signtime"));
                map.put("date", signtime);
                map.put("type", type);
                map.put("content", content);
                map.put("userName", userName);
                String inscriptionShow = StringUtils.null2String(m.get("inscriptionShow"));
                String image="";
                if(StringUtils.isNotBlank(inscriptionShow)){
                    String[] iss = inscriptionShow.split(",");
                    for(String is : iss){
                        switch (is){
                            case "signImg":
                                String picId = this.pendingTaskService.getSignPicId(userId);
                                if(StringUtils.isNotBlank(picId)){
                                    Map param2 = new HashMap();
                                    param2.put("fids", picId);
                                    try {
                                        String scopeMap1 = approveApiClient.getAttachmentInfos(param2, token);
                                        Map<String,Object> map1 = JsonUtils.readValue(scopeMap1);
                                        if(StringUtils.equals("success", StringUtils.null2String(map1.get("type")))){
                                            List<Map> attachment = (List<Map>)map1.get("data");
                                            if(attachment!=null && attachment.size()>0){
                                                image = StringUtils.null2String(attachment.get(0).get("imageUrl"));
                                            }
                                        }
                                    }catch (Exception e){
                                        LOG.error(" getAttachmentInfos  获取失败",e);
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
                map.put("image", image);
                messageList.add(map);
            }
        }

        return JSONObject.toJSONString(messageList);
    }

    /**
     * 获取批示意见信息
     */
    private Map<String, List<Map<String, Object>>> getComment(String processInstanceId, String userId, String corpId, String token){
        Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
        Map<String, String> hm = new HashMap<String, String>();
        hm.put("userId", userId);
        hm.put("corpId", corpId);
        hm.put("processInstanceId", processInstanceId);
        String jsonStr = approveApiClient.getCommentList( hm,token);
        Map<String, Object> jsonStrMap = JsonUtils.readValue(jsonStr);
        if (MapUtils.isNotEmpty(jsonStrMap)) {
            if ("success".equals(jsonStrMap.get("type"))) {
                Map<String, Object> map = (Map<String, Object>)jsonStrMap.get("data");
                List<Map<String, Object>> list = (List<Map<String, Object>>)map.get("commentList");
                if(list != null && !list.isEmpty()){
                    List<Map<String, Object>> commentListTemp = null;
                    for(Map<String, Object> m : list){
                        String field = StringUtils.null2String(m.get("field"));
                        if(result.get(field) == null){
                            commentListTemp = new ArrayList<Map<String, Object>>();
                            result.put(field, commentListTemp);
                        }else
                            commentListTemp = result.get(field);
                        commentListTemp.add(m);
                    }
                }
            }
        }
        return result;
    }

    /**
     * 获取公文字段值
     */
    private Map<String, Object> getDocumentFieldInfo(String receiveOrgId, String jgdzId, String sendFileNo, String jeremylevinComments, String id, String token){
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("jgdzId", jgdzId);
        paramMap.put("sendFileNo", sendFileNo);
        paramMap.put("receiveOrgId", receiveOrgId);
        paramMap.put("jeremylevinComments", jeremylevinComments);
        paramMap.put("creatDate", "");
        paramMap.put("id", id);
        String jsonStr = this.approveApiClient.getDocumentFieldInfo(paramMap,token);
        Map<String, Object> jsonStrMap = JsonUtils.readValue(jsonStr);
        if (MapUtils.isNotEmpty(jsonStrMap)) {
            if ("success".equals(jsonStrMap.get("type"))) {
                result = (Map<String, Object>)jsonStrMap.get("data");
            }
        }
        return result;
    }


    @ApiOperation(value = "流程收回", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "recoverReasonText", value = "收回原因", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderObject", value = "提醒对象：1-指定环节办理人  2-所有环节办理人 ", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "designActivity", value = "编辑字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/rollback", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult rollback(String taskId, String module, String processInstanceId, String recoverReasonText,
                                    String permissionCode, HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String designActivity = request.getParameter("designActivity");
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String dataId = request.getParameter("dataId");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        permissionCode = module + ":" + permissionCode + ":sh";
        if (StringUtils.isNotBlank(designActivity)) {
            if (designActivity.startsWith(",")) {
                designActivity = designActivity.substring(1);
            }
        }
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        List<Map> list = pendingTaskService.getTaskAndUser(processInstanceId, designActivity);
        List<Map> mapList = new ArrayList<>();
        ArrayList<String> receiver=new ArrayList<>();
        receiver.add(user.getUserId());
        if (null != list && list.size() > 0) {
            for (Map maps : list) {
                Map<String, String> m = new HashMap<String, String>();
                m.put("reminderContent", reminderContent);
                m.put("reminders", reminders);
                m.put("dataId", dataId);
                m.put("module", module);
                m.put("processTitle", title);
                m.put("processInstanceId", processInstanceId);
                m.put("sendId", user.getUserId());
                m.put("corpId", user.getCorpId());
                m.put("designActivity", designActivity);
                m.put("typeName", "收回");
                m.put("messageContent", recoverReasonText);
                m.put("taskId", maps.get("taskId") + "");
                m.put("userId", maps.get("userId") + "");
                m.put("formId", maps.get("formId") + "");
                m.put("nodeName", maps.get("nodeName") + "");
                m.put("taskType", "3");
                m.put("orgId", orgId);
                m.put("msgTitle", "流程收回提醒");
                mapList.add(m);
                receiver.add(maps.get("userId") + "");
            }
        }
        params.put("groupId", orgId);
        params.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        params.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        String taskIds = pendingTaskService.getAllTaskIds(user.getUserId(), user.getCorpId(), processInstanceId, user.getJwtToken());
        String json = approveApiClient.rollback( params,user.getJwtToken());
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
                Map m = new HashMap();
                m.put("taskId", taskIds);
                pendingTaskService.deleteUmcMessage(taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId, m, user.getUserId(), user.getCorpId(), user.getJwtToken());
                pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), recoverReasonText,
                        "2", pendingTaskService.getAllTaskIds(processInstanceId));

                pendingTaskService.sendReminder(mapList, user.getJwtToken());
            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程收回失败", e);
        }
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }

        return OperationResult.buildFailureResult("参数不能为空");
    }

    @ApiOperation(value = "判断是否可以收回", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/canRollback", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult canRollback(String taskId, HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        String json = approveApiClient.canRollback( params,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "流程反馈", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskUserIds", value = "任务用户ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "feedbackContent", value = "反馈内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "日志code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryCode", value = "流程分类编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/feedbackProcess", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult feedbackProcess(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> feedbackMap=new HashMap<String, String>();
        feedbackMap.put("taskUserIds",request.getParameter("taskUserIds"));
        feedbackMap.put("reminderContent",request.getParameter("reminderContent"));
        feedbackMap.put("feedbackContent",request.getParameter("feedbackContent"));
        feedbackMap.put("module",request.getParameter("module"));
        feedbackMap.put("permissionCode",request.getParameter("permissionCode"));
        feedbackMap.put("reminders",request.getParameter("reminders"));
        feedbackMap.put("processInstanceId",request.getParameter("processInstanceId"));
        feedbackMap.put("categoryCode",request.getParameter("categoryCode"));
        feedbackMap.put("formId",request.getParameter("formId"));
        feedbackMap.put("dataId",request.getParameter("dataId"));
        feedbackMap.put("processTitle",request.getParameter("processTitle"));
        feedbackMap.put("userId",user.getUserId());
        feedbackMap.put("corpId",user.getCorpId());
        feedbackMap.put("userName",user.getUserName());
        feedbackMap.put("cnName",user.getCnName());
        feedbackMap.put("token",user.getJwtToken());
        String permission = StringUtils.null2String(request.getParameter("module"))+":"+StringUtils.null2String(request.getParameter("permissionCode"))+":fk";
        boolean logStatus =logService.checkOptLog(user.getCorpId(), permission, feedbackMap.get("token"));
        try {
            pendingTaskExecutorService.feedbackProcess(request,feedbackMap);
            if(logStatus) {
                logService.saveModuleLog(permission, request.getParameter("processTitle"), null,null,request,"pc");
            }
        } catch (Exception e) {
            if (logStatus) {
                logService.saveModuleLog(permission, request.getParameter("processTitle"), null, UuidUtils.UUID(),request,"pc");
            }
            LOG.error("反馈失败",e);
        }
        ArrayList<String> receiver=new ArrayList<>();
        String taskUserIds = request.getParameter("taskUserIds");
        String[] split = taskUserIds.split(",");
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i].split(";")[2]);
        }

        //ws刷新 add by V4.4 2023-7-18 14:31:14
        WebsocketApproveConstant.refrashDealData(receiver);

        return OperationResult.buildSuccessResult();
    }

    @ApiOperation(value = "获取所有节点", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getAllActivity", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getAllActivity(String processInstanceId) {
        return OperationResult.buildSuccessResult(pendingTaskService.getAllActivity(processInstanceId));
    }

    @ApiOperation(value = "流程转发", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserIds", value = "转发用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "targetUserNames", value = "转发用户姓名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "业务数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "权限code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/forwardReadTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult forwardReadTask(String taskId, String targetUserIds, String targetUserNames,
                                           String module, String processInstanceId,
                                           String permissionCode, HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String menuType = request.getParameter("menuType");
        WebUser user = WebUtils.getCurrentUser();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        bodyParams.put("targetUserIds", targetUserIds);
        bodyParams.put("targetUserNames", targetUserNames);
        if (StringUtils.isNotBlank(reminders) && !"null".equals(reminders) && !"undefined".equals(reminders)) {
            bodyParams.put("msgType", reminders);
        }
        Map m = new HashMap();
        m.put("reminderContent", reminderContent);
        m.put("orgId", orgId);
        bodyParams.put("paramString", JsonUtils.writeValueAsString(m));
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        permissionCode = module + ":" + permissionCode + ":zfa";
        try {
            String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);

            this.pendingTaskService.forwardReadTaskSync(params, bodyDataParams, user.getJwtToken(), menuType, "", taskId );

            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null);
            }
            ArrayList<String> receiver=new ArrayList<>();
            receiver.add(user.getUserId());
            String[] split= targetUserIds.split(",");
            for (int i = 0; i < split.length; i++) {
                receiver.add(split[i]);
            }
            //ws刷新 add by V4.4 2023-7-18 14:31:14
            WebsocketApproveConstant.refrashDealData(receiver);

            return OperationResult.buildSuccessResult();
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
            }
            LOG.error("流程转发失败", e);
            return OperationResult.buildFailureResult("流程转发失败");
        }
    }

    @ApiOperation(value = "获取下属待办任务列表", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start", value = "页码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "没有人显示数量", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "流程code", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "category", value = "流程分类", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "title", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assignee", value = "办理人id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assigneeName", value = "办理人姓名", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getSubordinateTaskList", method = RequestMethod.GET)
    @ResponseBody
    public Page getSubordinateTaskList(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request,true);

        WebUser user = WebUtils.getCurrentUser();
        Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
        String index = request.getParameter("start");
        String limit = request.getParameter("limit");
        String code = request.getParameter("code");
        String category = request.getParameter("category");
        String title = request.getParameter("title");
        String module = request.getParameter("module");
        String assignee = request.getParameter("assignee");
        String assigneeName = request.getParameter("assigneeName");
        Map<String, String> map = new HashMap<String, String>();
        if (StringUtils.isNotBlank(assignee)) {
            map.put("assignee", assignee);
        }
        map.put("title", title);
        map.put("assigneeName", StringUtils.null2String(assigneeName));
        if (StringUtils.isBlank(index)) {
            index = "0";
        }
        if (StringUtils.isBlank(limit)) {
            limit = "10";
        }
        Map<String, String> userParams = new HashMap<String, String>();
        userParams.put("userId", user.getUserId());
        userParams.put("corpId", user.getCorpId());
        userParams.put("index", index);
        userParams.put("limit", limit);
        userParams.put("code", code);
        userParams.put("category", category);
        userParams.put("module", module);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        userParams.put("groupId", orgId);
        userParams.put("searchData", JsonUtils.writeValueAsString(map));
        String json = approveApiClient.getSubordinateTaskList( userParams,user.getJwtToken());
        Map<String, Object> m = JsonUtils.readValue(json);
        Map<String, Object> data = (Map<String, Object>) m.get("data");
        List<Map> list = (List<Map>) data.get("list");
        if (null != list && list.size() > 0) {
            for (Map maps : list) {
                String createTime = (String) maps.get("createTime");
                if (StringUtils.isNotBlank(createTime) && createTime.length() > 11) {
                    maps.put("createDay", createTime.substring(0, 10));
                    maps.put("createHour", createTime.substring(11));
                }
            }
        }

        //字段加密
        List<Map> list1 =  ApproveSecUtils.encryptData(list,"processInstanceId,id");

        return new PageImpl(list1, pageable, Long.valueOf(data.get("count").toString()).longValue());
    }

    @ApiOperation(value = "获取下属用户信息", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/getSubUserByUserId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getSubUserByUserId(HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> map = new HashMap<String, String>();
        map.put("userId", user.getUserId());
        map.put("type", "user");
        String json = approveApiClient.getSubUserByUserId( map,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取下属用户信息树", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/getSubUserTreeByUserId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getSubUserTreeByUserId(HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> map = new HashMap<String, String>();
        map.put("userId", user.getUserId());
        String json = approveApiClient.getSubUserByUserId( map,user.getJwtToken());
        Map<String, Object> m = JsonUtils.readValue(json);
        List<Map<String, Object>> list = (List<Map<String, Object>>) m.get("data");
        if (null != list && list.size() > 0) {
            StringBuffer str = new StringBuffer("");
            str.append("[");
            for (Map maps : list) {
                if (StringUtils.isNoneBlank((String) maps.get("id"))) {
                    str.append("{\"id\":\"").append(maps.get("id"))
                            .append("\",\"pId\":\"").append("\",\"name\":\"").append(maps.get("userName")).append("\"},");
                }
            }
            String str1 = str.toString();
            if (str1.endsWith(","))
                str1 = str1.substring(0, str1.length() - 1);
            str1 = (new StringBuilder()).append(str1).append("]").toString();
            return OperationResult.buildSuccessResult("请求成功", str1);
        }
        return OperationResult.buildSuccessResult("请求成功", "");
    }

    @ApiOperation(value = "流程减签操作", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userIds", value = "用户ids", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminders", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userNames", value = "用户名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/reduceSign", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult reduceSign(String taskId, String userIds, HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = request.getParameter("processInstanceId");

        //----------平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(  !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //----------平行越权  2022年6月15日18:52:50

        WebUser user = WebUtils.getCurrentUser();
        String reminderContent = request.getParameter("reminderContent");
        String reminders = request.getParameter("reminders");
        String title = request.getParameter("processTitle");
        String module = request.getParameter("module");
        String userNames = request.getParameter("userNames");


        String formId = request.getParameter("formId");
        String dataId = request.getParameter("dataId");

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("userIds", userIds);
        params.put("assigneeNames", userNames);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);

        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id

        String json = approveApiClient.reduceSign( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());
        //记录日志
        String permissionCode = module + ":pending:jianq";
        boolean logSet = logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken());
        if (StringUtils.isNotBlank(json)) {
            Map map = JsonUtils.readValue(json);
            if (StringUtils.equals("success", map.get("type") + "")) {
                List<Map> mapList = new ArrayList<>();
                String uids[] = userIds.split(",");
                for (int i = 0; i < uids.length; i++) {
                    Map<String, String> newMap = new HashMap<String, String>();
                    newMap.put("userId", uids[i]);
                    newMap.put("taskType", "3");
                    newMap.put("taskId", taskId);

                    newMap.put("processInstanceId", processInstanceId);
                    newMap.put("formId", formId);
                    newMap.put("dataId", dataId);

                    newMap.put("processTitle", title);
                    newMap.put("corpId", user.getCorpId());
                    newMap.put("reminderContent", reminderContent);
                    newMap.put("module", module);
                    newMap.put("reminders", reminders);
                    newMap.put("orgId", orgId);
                    newMap.put("sendId", user.getUserId());
                    newMap.put("msgTitle", "流程减签提醒");
                    mapList.add(newMap);
                }
                pendingTaskService.insertProcessMessage(mapList, user.getJwtToken());
                if (logSet) {
                    logService.saveModuleLog(permissionCode, title, null);
                }
            } else {
                if (logSet) {
                    logService.saveModuleLog(permissionCode, title, null, UuidUtils.UUID());
                }
            }
        }
        String[] split = userIds.split(",");
        ArrayList<String> receiver=new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            receiver.add(split[i]);
        }
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){

                //ws刷新 add by V4.4 2023-7-18 14:31:14
                WebsocketApproveConstant.refrashDealData(receiver);

                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = " 获取系统模块", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/getUmcModule", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUmcModule(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        List<Map> list = pendingTaskService.getModuleCateByCorpId(user.getCorpId());
        List<Map> newList = new ArrayList<Map>();
        if (null != list && list.size() > 0) {
            for (Map maps : list) {
                if (null != maps.get("module")) {
                    String module = maps.get("module").toString();
                    String moduleName = pendingTaskService.getAppNameByCode(module);
                    if (StringUtils.isNotBlank(module) && StringUtils.isNotBlank(moduleName)) {
                        maps.put("moduleCode", module);
                        maps.put("moduleName", moduleName);
                        newList.add(maps);
                    }
                }
            }
        }
        return OperationResult.buildSuccessResult(newList);
    }

    @ApiOperation(value = " 获取系统模块树", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/getUmcModuleTree", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUmcModuleTree(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        List<Map> list = bpmFollowService.getAllProcessModele(user.getCorpId());
        List<String> authList = cmpPermissionService.getUnauthModules();
        StringBuffer str = new StringBuffer("");
        str.append("[");
        for (Map map : list) {
            if (null != map.get("moduleCode")) {
                String moduleCode = map.get("moduleCode").toString();
                if (!authList.contains(moduleCode)) {
                    String appName = pendingTaskService.getAppNameByCode(moduleCode);
                    if (StringUtils.isNoneBlank(appName)) {
                        str.append((new StringBuilder()).append("{\"id\":\"").append(moduleCode)
                                .append("\",\"pId\":\"").append("\",\"name\":\"").append(appName)
                                .append("\"},"));
                    }
                }
            }
        }

        String str1 = str.toString();
        if (str1.endsWith(","))
            str1 = str1.substring(0, str1.length() - 1);
        str1 = (new StringBuilder()).append(str1).append("]").toString();
        return OperationResult.buildSuccessResult("请求成功", str1);
    }

    @ApiOperation(value = " 获取待办流程模块名称和icon ", notes = "")
    @RequestMapping(value = "/getUmcModuleIcon", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUmcModelByCorpId(HttpServletRequest request) {
        List<Map> list = bpmFollowService.getAppInfoMap();
        List<Map> ms = new ArrayList<Map>();
        if(null!=list && list.size()>0){
            List<String> authList = cmpPermissionService.getUnauthModules();
            for(Map m : list){
                String moduleCode = m.get("moduleCode").toString();
                if (!authList.contains(moduleCode)) {
                    if (StringUtils.isNotBlank((String) m.get("appName"))) {
                        ms.add(m);
                    }
                }
            }
        }
        return OperationResult.buildSuccessResult(ms);
        /*WebUser user = WebUtils.getCurrentUser();
        List<Map> list = bpmFollowService.getAllProcessModele(user.getCorpId());
        List<String> authList = cmpPermissionService.getUnauthModules();
        List<Map<String, String>> ms = new ArrayList<Map<String, String>>();
        if (null != list && list.size() > 0) {
            for (Map m : list) {
                String moduleCode = m.get("moduleCode").toString();
                if (!authList.contains(moduleCode)) {
                    Map<String, String> iconParams = new HashMap<String, String>();
                    Map<String, String> map = new HashMap<String, String>();
                    iconParams.put("appCode", moduleCode);
                    String jsonIcon = approveApiClient.getAppInfoListByAppCode( iconParams ,user.getJwtToken());
                    Map<String, Object> iconm = JsonUtils.readValue(jsonIcon);
                    Map<String, Object> dataicon = (Map<String, Object>) iconm.get("data");
                    map.put("moduleCode", (String) dataicon.get("appCode"));
                    map.put("moduleName", (String) dataicon.get("appName"));
                    map.put("moduleIcon", (String) dataicon.get("icon"));
                    map.put("iconColor", (String) dataicon.get("iconColor"));
                    if (StringUtils.isNotBlank((String) dataicon.get("appName"))) {
                        ms.add(map);
                    }
                }
            }
        }
        return OperationResult.buildSuccessResult(ms);
*/
    }

    @ApiOperation(value = "根据ids获取用户集合", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIds", value = "用户ids", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getUserListByIds", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUserListByIds(HttpServletRequest request) {
        String userIds = request.getParameter("userIds");
        WebUser user = WebUtils.getCurrentUser();
        List list = userApiService.getUserByIdsAndCorpId(userIds, user.getCorpId(), user.getJwtToken());
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "根据ids获取附件集合", notes = "")
    @RequestMapping(value = "/getAttachmentByIds", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getAttachmentByIds(HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();
        List<Map<String, String>> attLsit = new ArrayList();
        String ids = StringUtils.null2String(request.getParameter("ids"));
        if (StringUtils.isNoneBlank(ids)) {
            attLsit = attachmentUtilsService.getAttachmentByIds(ids, corpId, token);
        }

        return OperationResult.buildSuccessResult(attLsit);
    }

    @ApiOperation(value = "根据流程实例id获取流程标题", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getTitleByProInsId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getTitleByProInsId(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String flowTitle = "";
        Map<String, String> map = new HashMap<String, String>();
        if (StringUtils.isNoneBlank(processInstanceId)) {
            flowTitle = this.pendingTaskService.getTitleByProInsId(processInstanceId);
            map.put("flowTitle", flowTitle);
            return OperationResult.buildSuccessResult(map);
        } else {
            return OperationResult.buildFailureResult("标题获取失败");
        }
    }

    @ApiOperation(value = "获取消息面板数据", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelflag", value = "关联模块标识", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "linkid", value = "外部关联id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskid", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "数据类型：attachment(只获取附件区信息), commentReply(只获取批示意见回复信息), messageReply(只获取留言回复信息), all(获取所有信息)", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getMessageboardInfo", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getMessageboardInfo(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //关联模块标识
        String modelflag = StringUtils.null2String(request.getParameter("modelflag"));
        //外部关联id
        String linkid = StringUtils.null2String(request.getParameter("linkid"));
        //任务id
        String taskid = StringUtils.null2String(request.getParameter("taskid"));
        //数据类型：attachment(只获取附件区信息), commentReply(只获取批示意见回复信息), messageReply(只获取留言回复信息), all(获取所有信息)
        String type = StringUtils.null2String(request.getParameter("type"));
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> map = new HashMap<String, String>();
        map.put("modelflag", modelflag);
        map.put("linkid", linkid);
        map.put("taskid", taskid);
        map.put("type", type);
        String json = approveApiClient.getMessageboardInfo( map ,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "呈领导", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leaderId", value = "关联模块标识", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "leaderName", value = "外部关联id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "msgType", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealTips", value = "办理提示", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/toLeaderTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult toLeaderTask(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();

        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }

        //任务id
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        //领导id
        String leaderId = StringUtils.null2String(request.getParameter("leaderId"));
        //领导Name
        String leaderName = StringUtils.null2String(request.getParameter("leaderName"));
        //流程实例id
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));

        //提醒方式 和内容  {提醒方式msgType消息内容paramString办理提示dealTips}
        String msgType = StringUtils.null2String(request.getParameter("msgType"));
        String reminderContent = StringUtils.null2String(request.getParameter("reminderContent"));
        String dealTips = StringUtils.null2String(request.getParameter("dealTips"));

        if (StringUtils.isNoneBlank(taskId) && StringUtils.isNoneBlank(leaderId)) {
            Map<String, String> dataMap = new HashMap<String, String>();
            dataMap.put("msgType", msgType);
            dataMap.put("dealTips", dealTips);

            Map m = new HashMap();
            m.put("reminderContent", reminderContent);
            m.put("orgId", orgId);
            dataMap.put("paramString", JsonUtils.writeValueAsString(m));
            dataMap.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
            dataMap.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
            String bodyDataParams = JsonUtils.writeValueAsString(dataMap);

            Map<String, String> map = new HashMap<String, String>();
            map.put("userId", userId);
            map.put("corpId", corpId);
            map.put("groupId", orgId);
            map.put("taskId", taskId);
            map.put("leaderId", leaderId);
            map.put("leaderName", leaderName);

            String json = approveApiClient.toLeaderTask( map ,bodyDataParams,user.getJwtToken());
            Map<String, Object> map1 = JsonUtils.readValue(json);
            if ("success".equals(map1.get("type").toString())) {
                Map m1 = new HashMap();
                m1.put("taskId", taskId);
                Map m2=pendingTaskService.getModuleProIdByTaskId(taskId);
                pendingTaskService.takeMsgDoneSleep(m2.get("module")+"", m2.get("processInstanceId")+"", m1, user.getUserId(), user.getCorpId(), user.getJwtToken());
                if(StringUtils.isNotBlank(processInstanceId)){
                    this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
                }
            }
            return pendingTaskService.stringToOperation(json);
        } else {
            return OperationResult.buildFailureResult("操作失败");
        }

    }

    @ApiOperation(value = "获取任务信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getTaskInfoByProTasId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getTaskInfoByProTasId(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String userId = StringUtils.null2String(request.getParameter("userId"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        List<Map> list = pendingTaskService.getTaskInfoByProTasId(processInstanceId, userId, taskId);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "根据节点id获取批示意见", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskDefKey", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuType", value = "菜单类型", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isReplyComment", value = "是否可回复", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "enableCommentArea", value = "批示意见是否显示", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentField", value = "批示意见", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getCommentListByDefKey", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getCommentListByDefKey(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String userId = StringUtils.null2String(request.getParameter("userId"));
        String taskDefKey = StringUtils.null2String(request.getParameter("taskDefKey"));//节点id

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String menuType = StringUtils.null2String(request.getParameter("menuType"));
        String isReplyComment = StringUtils.null2String(request.getParameter("isReplyComment"));
        String enableCommentArea = StringUtils.null2String(request.getParameter("enableCommentArea"));
        String commentField = StringUtils.null2String(request.getParameter("commentField"));

        Map<String, String> map = new HashMap<String, String>();
        map.put("userId", userId);
        map.put("corpId", corpId);
        map.put("processInstanceId", processInstanceId);
        map.put("taskDefKey", taskDefKey);
        map.put("commentField", commentField);

        String json = approveApiClient.getCommentListByDefKey( map ,user.getJwtToken());

        List<Map> commentList = new ArrayList();
        if (StringUtils.isNotBlank(json)) {
            Map<String, Object> m = JsonUtils.readValue(json);
            commentList = (List<Map>) m.get("data");
        }

        boolean isNotShowReply = true;
        if (StringUtils.equals("query", menuType)) {//流程查询不需要批示意见回复
            isNotShowReply = true;
        } else {
            if (StringUtils.equals("0", isReplyComment)) {
                isNotShowReply = true;
            } else if (StringUtils.equals("1", enableCommentArea)) {
                isNotShowReply = false;
            } else {
                Map<String, String> pm = new HashMap<String, String>();
                pm.put("processInstanceId", processInstanceId);
                String pjson = approveApiClient.getProcessAreaSet( pm ,user.getJwtToken());
                Map<String, Object> pMap = JsonUtils.readValue(pjson);
                Map<String, Object> m = (Map<String, Object>) pMap.get("data");
                String eca = m.get("enableCommentArea") + "";
                if (StringUtils.equals("1", eca)) {
                    isNotShowReply = false;
                }
            }
        }

        List<Map> newCommentList = new ArrayList();
        String commentInfo = "";
        if (commentList != null && commentList.size() > 0) {
            commentInfo += "[";
            for (Map newMap : commentList) {
                String commentType = StringUtils.null2String(newMap.get("type"));
                String inscriptionShow = StringUtils.null2String(newMap.get("inscriptionShow"));
                String orgShowType = StringUtils.null2String(newMap.get("orgShowtype"));
                String replacename = StringUtils.null2String(newMap.get("replacename"));
                Object replaceid = StringUtils.null2String(newMap.get("replaceid"));
                String commentReply = StringUtils.null2String(newMap.get("canreply"));
                String showReplaceUser = StringUtils.null2String(newMap.get("showReplaceUser"));
                if (!StringUtils.equals("1", showReplaceUser)) {
                    replacename = "";
                    replaceid = "";
                }

                if (isNotShowReply) {
                    commentReply = "";
                }

                String commentTypes = commentType;
                if (commentTypes.indexOf("image") != -1) {
                    commentTypes = "sign";
                } else if (commentTypes.indexOf("text") != -1) {
                    commentTypes = "text";
                }

                String dataTime = StringUtils.null2String(newMap.get("time"));
                String date = dataTime.substring(0, 10);
                String time = dataTime.substring(11);
                String isSignPic = "0";
                if (StringUtils.isNotBlank(inscriptionShow) && inscriptionShow.indexOf("signImg") != -1) {
                    isSignPic = "1";
                }
                String active = "0";

                String fullMessage = StringUtils.null2String(newMap.get("fullMessage"));
                if (fullMessage == null) {
                    fullMessage = "";
                } else {
                    fullMessage = fullMessage.replaceAll("\\\\", "\\\\\\\\");
                    fullMessage = (fullMessage + "").replaceAll("\"", "\\\\\"");
                }

                newMap.put("time", time);
                newMap.put("date", date);
                newMap.put("commentReply", commentReply);
                newMap.put("inscriptionShow", inscriptionShow);
                newMap.put("orgShowType", orgShowType);
                newMap.put("replacename", replacename);
                newMap.put("isSignPic", isSignPic);
                newMap.put("active", active);
                newMap.put("type", commentTypes);
                newMap.put("taskDefKey", taskDefKey);
                newMap.put("processInstanceId", processInstanceId);
                newMap.put("fullMessage", fullMessage);
                newCommentList.add(newMap);
            }
        }
        return OperationResult.buildSuccessResult(newCommentList);
    }

    @ApiOperation(value = "根据流程实例id获取发起人id", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getStartUserIdByInstanceId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getStartUserIdByInstanceId(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        Map map = pendingTaskService.getStartUserByProId(processInstanceId);
        return OperationResult.buildSuccessResult(map);
    }

    @ApiOperation(value = "根据流程实例id和用户id获取办理提示状态", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getDealtipsStatusByInstanceIdAndUserId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getDealtipsStatusByInstanceIdAndUserId(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        List<BpmProcessDealtips> bpd = bpmProcessDealtipsService.getDealtipsStatusByInstanceIdAndUserId(userId, taskId, processInstanceId);
        return OperationResult.buildSuccessResult(bpd);
    }

    @ApiOperation(value = "更新办理提示状态", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/updateDealtipsStatus", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult updateDealtipsStatus(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        try {
            bpmProcessDealtipsService.updateDealtipsStatus(userId, taskId, processInstanceId);
            return OperationResult.buildSuccessResult();
        } catch (Exception e) {
            LOG.error("更新失败", e);
            return OperationResult.buildFailureResult("更新失败");
        }
    }

    @ApiOperation(value = "根据流程实例id和用户id获取流程记录和批示意见", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "类型1-显示主要所有记录2-显示主要批示意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowClaim", value = "0-隐藏签收记录 1-显示签收记录", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isChildProcess", value = "是否是子流程", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getFlowLogCommentList", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getFlowLogCommentList(HttpServletRequest request, String taskId, String type, String processInstanceId) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String isShowClaim = StringUtils.null2String(request.getParameter("isShowClaim"));
        String isChildProcess = StringUtils.null2String(request.getParameter("isChildProcess"));

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("type", type);
        params.put("processInstanceId", processInstanceId);
        params.put("isShowClaim", isShowClaim);
        params.put("isChildProcess", isChildProcess);
        String json = approveApiClient.getFlowLogCommentList( params ,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "根据流程实例id和用户id获取流程记录和批示意见", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowClaim", value = " 0-隐藏签收记录 1-显示签收记录", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowMainComments", value = " 是否显示主要意见   1-显示所有流程记录 2-显示主要意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isChildProcess", value = "是否是子流程", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "searchOrgIds", value = "搜索 填写意见的组织id2  多个逗号分割", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShowNodeal", value = "是否显示未办理操作 0否", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getFlowLogCommentListNew", method = RequestMethod.GET)
    @ResponseBody
    public Page  getFlowLogCommentListNew(HttpServletRequest request, String taskId,  String processInstanceId) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request,true);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if( ( !ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode))){
            Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
            Page page = new PageImpl(new ArrayList(), pageable, 0);
            return page;
        }
        //---------- 平行越权  2022年6月15日18:52:50

        //是否显示签收记录 0-隐藏 1-显示
        String isShowClaim = ValidateUtils.filter(StringUtils.null2String(request.getParameter("isShowClaim")));

        String isChildProcess = ValidateUtils.filter(StringUtils.null2String(request.getParameter("isChildProcess")));


        //是否显示主要意见   1-显示所有流程记录 2-显示主要意见
        String isShowMainComments = (StringUtils.null2String(request.getParameter("isShowMainComments")));
        //隐藏未办理记录
        String isShowNodeal = (StringUtils.null2String(request.getParameter("isShowNodeal")));

        //搜索 参与者
        String searchDealusername = ValidateUtils.filter(StringUtils.null2String(request.getParameter("searchDealusername")));

        //搜索 填写意见的组织id2  多个逗号分割
        String searchOrgIds = ValidateUtils.filter(StringUtils.null2String(request.getParameter("searchOrgIds")));

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String corpId = user.getCorpId();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        params.put("type", isShowMainComments);
        params.put("processInstanceId", processInstanceId);
        params.put("isShowClaim", isShowClaim);
        params.put("searchDealusername", searchDealusername);
        params.put("searchOrgIds", searchOrgIds);
        params.put("isChildProcess", isChildProcess);
        params.put("isShowNodeal", isShowNodeal);
        String json = approveApiClient.getFlowLogCommentList( params ,user.getJwtToken());

        Map<String,Object> result = new HashMap<>();
        List<Map> logList = new ArrayList<>();

        if(StringUtils.isNotBlank(json)){
            Map map = JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                logList =  (List<Map>)map.get("data");
            }else{
                LOG.error("获取流程记录失败："+map.get("message")+"", map.get("data"));
            }
        }
        Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
        Page page = new PageImpl(logList, pageable, Long.valueOf(logList.size()).longValue());
        return page;
    }

    @ApiOperation(value = "校验流程是否可办理", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/judgeSeizeTask", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult judgeSeizeTask(HttpServletRequest request, String taskId) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("id"+taskId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String userId = StringUtils.null2String(request.getParameter("userId"));
        if (StringUtils.isBlank(userId)) {
            userId = user.getUserId();
        }

        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("taskId", taskId);
        String json = approveApiClient.judgeSeizeTask( params ,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取流程设置信息", notes = "")
    @RequestMapping(value = "/getProcessAreaSet", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getProcessAreaSet(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String token = user.getJwtToken();
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        Map<String, String> pm = new HashMap<String, String>();
        pm.put("processInstanceId", processInstanceId);
        pm.put("taskId", taskId);
        String pjson = approveApiClient.getProcessAreaSet( pm ,user.getJwtToken());
        Map<String, Object> pMap = JsonUtils.readValue(pjson);
        return OperationResult.buildSuccessResult(pMap);
    }

    @ApiOperation(value = "获取表单签批记录列表", notes = "")
    @RequestMapping(value = "/getBpmProcessHiFormofdList", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "版本记录状态  1-正常  0-临时  -1 删除", required = false, paramType = "query", dataType = "String"),
    })
    @ResponseBody
    public OperationResult getBpmProcessHiFormofdList(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        if(StringUtils.isBlank(processInstanceId)){
            return OperationResult.buildFailureResult("processInstanceId不能为空！");
        }
        String status = StringUtils.null2String(request.getParameter("status"));
        if(StringUtils.isBlank(status)){//默认获取正常的记录
            status = "1";//版本记录状态  1-正常  0-临时  -1 删除
        }
        Map<String, List<Map>> resultMap = bpmProcessHiFormofdService.getBpmProcessHiFormofdList(processInstanceId, status);
        return OperationResult.buildSuccessResult(resultMap);
    }

    @ApiOperation(value = "获取正文编辑锁信息", notes = "")
    @RequestMapping(value = "/getTextlock", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "textFieldName", value = "正文字段名称  表名_字段名", required = false, paramType = "query", dataType = "String"),
    })
    @ResponseBody
    public OperationResult getTextlock(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String token = user.getJwtToken();

        //删除超期的正文锁  超期的 进行删除解锁   默认30分钟 去配置文件 参数
        String lockTime = GlobalConstant.getConfig("app.flexoffice.text_lock_time");
        if(StringUtils.isBlank(lockTime)){
            lockTime = "30";
        }
        int  mins = 30;
        try{
            mins = Integer.parseInt(lockTime);
        }catch(Exception e){
            LOG.error("getTextlock 类型转换异常：", e);
        }

        bpmProcessTextlockService.delTextlock(mins);

        String textFieldName = StringUtils.null2String(request.getParameter("textFieldName"));
        List<Map> list = bpmProcessTextlockService.getTextlock(processInstanceId,textFieldName,null);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "插入正文编辑锁信息", notes = "")
    @RequestMapping(value = "/addTextlock", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "textFieldName", value = "正文字段名称  表名_字段名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "锁状态：1-上锁 0-解锁 2-被解锁", required = false, paramType = "query", dataType = "String"),
    })
    @ResponseBody
    public OperationResult addTextlock(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String token = user.getJwtToken();

        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String textFieldName = StringUtils.null2String(request.getParameter("textFieldName"));
        //锁状态：1-上锁 0-解锁 2-被解锁
        String status = StringUtils.null2String(request.getParameter("status"));
        String id = bpmProcessTextlockService.addTextlock(processInstanceId,taskId,textFieldName,userId);
        return OperationResult.buildSuccessResult(id);
    }

    @ApiOperation(value = "解锁 正文编辑锁", notes = "")
    @RequestMapping(value = "/updateTextlockStatus", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "textFieldName", value = "正文字段名称  表名_字段名", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "锁状态：1-上锁 0-解锁 2-被解锁", required = false, paramType = "query", dataType = "String"),
    })
    @ResponseBody
    public OperationResult updateTextlockStatus(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String token = user.getJwtToken();
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String textFieldName = StringUtils.null2String(request.getParameter("textFieldName"));
        //锁状态：1-上锁 0-解锁 2-被解锁
        String status = StringUtils.null2String(request.getParameter("status"));
        if(status.length() == 0){//默认上锁
            status = "1";
        }

        String id = "";
        if("1".equals(status)){//上锁
            id = bpmProcessTextlockService.addTextlock(processInstanceId,taskId,textFieldName,userId);
        }else if("0".equals(status)){//解锁
            id = bpmProcessTextlockService.unTextlock(processInstanceId,userId);
        }
        return OperationResult.buildSuccessResult(id);
    }

    @ApiOperation(value = "修改抢占待办任务状态", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/editUndoTaskStatus", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult updateTextlockStatus(String taskId,HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", user.getUserId());
        params.put("userName", user.getCnName());
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("orgId", orgId);
        String json = approveApiClient.editUndoTaskStatus( params ,user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "获取操作记录中填写意见人的组织信息树", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "procInstIds", value = "流程实例ids  逗号分割", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getCommentOrgTreelist", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getCommentOrgTreelist( String procInstIds,HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        List<Map<String, Object>> orgList = new ArrayList<>();

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> map = new HashMap<String, String>();
        map.put("procInstIds", procInstIds);
        String json = approveApiClient.getCommentOrgTreelist( map,user.getJwtToken());
        Map<String, Object> m = JsonUtils.readValue(json);
        List<Map<String, Object>> list = (List<Map<String, Object>>) m.get("data");
        if (null != list && list.size() > 0) {
            String orgIds = "";
            for (Map maps : list) {
                if (StringUtils.isNoneBlank((String) maps.get("id"))) {
                    orgIds += maps.get("id")+",";
                }
            }
            if(orgIds.endsWith(",")){
                orgIds = orgIds.substring(0,orgIds.length()-1);
            }

            List<String> limitOrgIds = new ArrayList<>();
            if(StringUtils.isNotBlank(orgIds)){
                limitOrgIds = cmpSystemDataService.getParentOrgByOrgIds(Arrays.asList(orgIds.split(",")));
            }

            Map<String, String> params = new HashMap<String, String>();
            params.put("queryLimit", "3");
            params.put("limitData", StringUtils.join(limitOrgIds,","));
            params.put("limitPart", "");
            params.put("limitScope", "");
            params.put("usersecretlevel", "4");
            params.put("exRanges", "");
            params.put("exCustScope", "");
            params.put("exPerCode", "");
            params.put("orgType", "");
            params.put("async", "true");
            params.put("searchData","");

            String orgjson = this.approveApiClient.getOrgTree(params,user.getJwtToken());
            if (StringUtils.isNotBlank(orgjson)) {
                Map<String, Object> orgmap = JsonUtils.readValue(orgjson);
                String type = StringUtils.null2String(orgmap.get("type"));
                if (null != type && type.equals("success")) {//判断是否返回正常
                    String treeJson = StringUtils.null2String(orgmap.get("data"));
                    orgList = JsonUtils.readListValue(treeJson);
                }
            }

            return OperationResult.buildSuccessResult("请求成功", orgList);
        }
        return OperationResult.buildSuccessResult("请求成功", "");
    }


    @ApiOperation(value = "获取操作记录中填写意见人的组织信息树", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "procInstIds", value = "流程实例ids  逗号分割", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getProcessStatusById", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getProcessStatusById( String procInstIds,HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> map = new HashMap<String, String>();
        map.put("procInstIds", procInstIds);
        String json = approveApiClient.getCommentOrgTreelist( map,user.getJwtToken());
        Map<String, Object> m = JsonUtils.readValue(json);
        List<Map<String, Object>> list = (List<Map<String, Object>>) m.get("data");
        if (null != list && list.size() > 0) {
            StringBuffer str = new StringBuffer("");
            str.append("[");
            for (Map maps : list) {
                if (StringUtils.isNoneBlank((String) maps.get("id"))) {
                    str.append("{\"id\":\"").append(maps.get("id"))
                            .append("\",\"pId\":\"").append("\",\"name\":\"").append(maps.get("name")).append("\"},");
                }
            }
            String str1 = str.toString();
            if (str1.endsWith(","))
                str1 = str1.substring(0, str1.length() - 1);
            str1 = (new StringBuilder()).append(str1).append("]").toString();
            return OperationResult.buildSuccessResult("请求成功", str1);
        }
        return OperationResult.buildSuccessResult("请求成功", "");
    }

    @ApiOperation(value = "获取流程状态信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "procInstIds", value = "流程实例ids  逗号分割", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getProcessDealStatus", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getProcessDealStatus( String procInstIds,HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        List<Map<String, Object>> list = new ArrayList<>();
        try{
            WebUser user = WebUtils.getCurrentUser();
            Map<String, String> map = new HashMap<String, String>();
            map.put("procInstIds", procInstIds);
            String json = approveApiClient.getProcessDealStatus( map,user.getJwtToken());
            Map<String, Object> m = JsonUtils.readValue(json);
            list = (List<Map<String, Object>>) m.get("data");
        }catch(Exception e){
            LOG.error("获取流程状态信息",e);
            return OperationResult.buildFailureResult("getProcessDealStatus：获取流程状态信息！");
        }

        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "导出表单为wps文件", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileContent", value = "表单内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "flowTitle", value = "流程标题", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "moduleCode", value = "模块编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/exportHtmlToWps", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult exportHtmlToWps(HttpServletRequest request,HttpServletResponse response, @RequestParam("fileContent") String fileContent,
                                @RequestParam("moduleCode") String moduleCode, @RequestParam("flowTitle") String flowTitle, String processTitle){

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        if (StringUtils.isNotBlank(fileContent)) {
            try{
                fileContent = new String(Base64.getDecoder().decode(fileContent),"UTF-8");
            }catch(Exception e){
                LOG.error("Base64 decode 失败：",e);
                return OperationResult.buildFailureResult("表单内容解码失败！");
            }
        }else{
            return OperationResult.buildFailureResult("表单内容不能为空！");
        }

        WebUser user = WebUtils.getCurrentUser();
        List<java.util.Map<String, Object>> fileInfo = this.pendingTaskService.exportHtmlToWps(fileContent, flowTitle, moduleCode,user.getJwtToken(), request, response);
        return OperationResult.buildSuccessResult(fileInfo);
    } 

    @ApiOperation(value = "获取移动端手写签批意见附件信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "signId", value = "手写签批id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "signType", value = "手写签批类型", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getImageBySignId", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getImageBySignId( HttpServletRequest request,String signId, String signType) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();
        List<Map<String,String>> list = this.pendingTaskService.getImageBySignId(signId, signType, corpId, token);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "获取个人群组树信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "id串", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "searchData", value = "查询项", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getPersonalgrpUserTreeById", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getPersonalgrpUserTreeById( HttpServletRequest request,String ids ) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();

        String searchData = StringUtils.null2String(request.getParameter("searchData"));

        List<Map<String,Object>> list = this.pendingTaskService.getPersonalgrpUserTreeById(ids, searchData, corpId, token);
        return OperationResult.buildSuccessResult(list);
    }

    @ApiOperation(value = "批量暂不处理", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "待办任务id，多个逗号分割", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isDeal", value = " 状态（1暂不处理 0恢复暂不处理）", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/updateTaskDealType", method = RequestMethod.POST)
    @ResponseBody
    @WebsocketCode({WebsocketConstant.UNITEDAPPROVE})
    public OperationResult updateTaskDealType( HttpServletRequest request,String taskId , String isDeal) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();

        String json = this.pendingTaskService.updateTaskDealType(taskId, isDeal, corpId, token);
        ArrayList<String> receiver=new ArrayList<>();
        receiver.add(user.getUserId());
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                WebsocketUtils.setReceiverById(receiver);
                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }
        return OperationResult.buildFailureResult("参数不能为空");
    }

    @ApiOperation(value = "批量校验表单必填", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskIds", value = "待办任务id，多个逗号分割", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/batchValidateForm", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult batchValidateForm( HttpServletRequest request,String taskIds) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String token = user.getJwtToken();

        String json = this.pendingTaskService.batchValidateForm(taskIds, corpId, token);
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "部门办理", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "待办任务id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departType", value = "部门办理  1-本部门   2-本部门及下级", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/departDeal", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult departDeal( HttpServletRequest request,String module, String processInstanceId, String taskId,String departType) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        if(StringUtils.isBlank(taskId) || StringUtils.isBlank(departType)){
            LOG.error("部门办理 参数不能为空  taskId："+taskId+"   departType:"+departType);
            return OperationResult.buildFailureResult("操作失败");
        }

        WebUser user = WebUtils.getCurrentUser();
        String userId = user.getUserId();
        String token = user.getJwtToken();
        String corpId = user.getCorpId();

        String json = this.pendingTaskService.departDeal( module, processInstanceId, taskId, departType, userId, corpId, token);

        //ws刷新 add by V4.4 2023-7-18 14:31:14
       // WebsocketApproveConstant.refrashDealData(null);

        return pendingTaskService.stringToOperation(json);
    }




    @ApiOperation(value = "流程挂起", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "msgType", value = "提醒方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealName", value = "操作名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "handUpReason", value = "挂起原因", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/handUpProcessInstance", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult handUpProcessInstance( HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        Map<String, String> params = new HashMap<String, String>();
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String userId=user.getUserId();
        String token = user.getJwtToken();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        String processInstanceId= StringUtils.null2String(request.getParameter("processInstanceId"));
        String reminderContent = StringUtils.null2String(request.getParameter("reminderContent"));
        String handUpReason = StringUtils.null2String(request.getParameter("handUpReason"));
        String dealName = StringUtils.null2String(request.getParameter("dealName"));
        String reminders = request.getParameter("reminders");

        params.put("userId",userId);
        params.put("corpId",corpId);
        params.put("orgId",orgId);
        params.put("processInstanceId",processInstanceId);

        bodyParams.put("msgType",reminders);
        bodyParams.put("reminderContent",reminderContent);
        bodyParams.put("handUpReason",handUpReason);
        bodyParams.put("dealName",dealName);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
        String json = this.approveApiClient.handUpProcessInstance(params,bodyDataParams,token);
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }
        return OperationResult.buildFailureResult("参数不能为空");
    }

    @ApiOperation(value = "流程恢复", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "msgType", value = "提醒方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "reminderContent", value = "提醒内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealName", value = "操作名称", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/recoveryHandUpProInst", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult recoveryHandUpProInst( HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String userId=user.getUserId();
        String token = user.getJwtToken();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        Map<String, String> params = new HashMap<String, String>();
        String processInstanceId= StringUtils.null2String(request.getParameter("processInstanceId"));
        String reminderContent = StringUtils.null2String(request.getParameter("reminderContent"));
        String dealName = StringUtils.null2String(request.getParameter("dealName"));
        String reminders = request.getParameter("reminders");
        params.put("userId",userId);
        params.put("corpId",corpId);
        params.put("orgId",orgId);
        params.put("processInstanceId",processInstanceId);

        bodyParams.put("msgType",reminders);
        bodyParams.put("reminderContent",reminderContent);
        bodyParams.put("dealName",dealName);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        String bodyDataParams = JsonUtils.writeValueAsString(bodyParams);
        String json = this.approveApiClient.recoveryHandUpProInst(params,bodyDataParams,token);
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }
        return OperationResult.buildFailureResult("参数不能为空");
    }

    @ApiOperation(value = "打开办理/新增/查看页面", notes = "")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/loadFlowInfo", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult loadFlowInfo(HttpServletRequest request) {

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        OperationResult res = this.pendingTaskService.loadFlowInfo(request);
        return res;
    }


    @ApiOperation(value = "获取发起流程地址", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processCode", value = "流程code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "relationProcessInstanceId", value = "需要关联的流程实例id", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getstartProcessUrl", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getstartProcessUrl(HttpServletRequest request,String processCode, String relationProcessInstanceId) {
        LOG.debug("获取发起流程地址  getstartProcessUrl  ...............................");
        LOG.debug("processCode="+processCode);
        LOG.debug("relationProcessInstanceId="+relationProcessInstanceId);

        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);

        WebUser user = WebUtils.getCurrentUser();

        String userId = user.getUserId();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        String orgName = user.getOrgName();
        String userName = user.getCnName();
        String token = user.getJwtToken();

        Map<String, Object> bodyParams = new HashMap<String, Object>();
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);
        params.put("corpId", "0");

        params.put("groupId", orgId);
        params.put("code", ValidateUtils.filter(processCode));
        bodyParams.put("orgName", orgName);
        bodyParams.put("userName", userName);

        String processInstanceId = "";//流程实例id
        String taskId = "";//当前任务id
        String formKey = "";//表单id
        String processName = "";//流程民称
        String processTitle = "";//流程标题
        Map<String,Object> formMapData = new HashMap<>();

        String openUrl ="";

        String secdatacode = "";
        try {
            ObjectMapper mapper = new ObjectMapper();
            String bodyDataParams = mapper.writeValueAsString(bodyParams);
            String json = approveApiClient.startProcess( params,bodyDataParams,token);
            Map<String, Object> m = JsonUtils.readValue(json);
            if(StringUtils.equals("success", m.get("type")+"")){
                Map<String, Object> data = (Map<String, Object>) m.get("data");
                processInstanceId = StringUtils.null2String(data.get("processInstanceId"));
                taskId = StringUtils.null2String(data.get("openTaskId"));
                List<Map<String,Object>> list = (List<Map<String,Object>>)data.get("list");
                if(list!=null && list.size()>0){
                    String category = StringUtils.null2String(list.get(0).get("category"));
                    processName = StringUtils.null2String(list.get(0).get("processName"));
                    processTitle = StringUtils.null2String(list.get(0).get("title"));
                    formKey = StringUtils.null2String(list.get(0).get("formKey"));
                    String module = StringUtils.null2String(list.get(0).get("module"));
                    Map dataMap = new HashMap<>();
                    dataMap.put("processInstanceId",processInstanceId);
                    dataMap.put("id",taskId);

                    if(StringUtils.isNotBlank(relationProcessInstanceId)){
                        pendingTaskService.insertBatchRelation(relationProcessInstanceId,processInstanceId, "");
                    }

                    dataMap = ApproveSecUtils.encryptData(dataMap,"processInstanceId,id");
                    secdatacode = StringUtils.null2String(dataMap.get(""));
                    if("goa_document".equals(module)){
                        openUrl ="/web/dist/goa/document/sendFlow/pendingTask_view.html?window=1&businesskey=&edittype=add&bpmnxml=&category="+category+"&symbolid=&defineid=40289ead8856e66e01885700812904cb&processinstanceid="+processInstanceId+"&menutype=start&processname="+processName+"&formkey="+formKey+"&taskid="+taskId+"&permissioncode=start&approvedatacode="+secdatacode+"&relationProcessInstanceId="+relationProcessInstanceId;
                    }else{
                        openUrl = "/web/dist/modules/approve/pending/pendingtask_view.html?window=1&formkey="+formKey+"&processinstanceid="+processInstanceId+"&businesskey=&category="+category+"&flowparamjson=&parentprocessinstanceid=&parenttaskid=&secdatacode="+secdatacode+"&parentactivityid=&taskid="+taskId+"&edittype=add&menutype=start&permissioncode=start&flowcode="+module+"&relationProcessInstanceId="+relationProcessInstanceId;
                    }
                }
            }else{
                //判断是否三方流程
                if(StringUtils.equals("三方流程不支持发起",m.get("message")+"")){
                    return OperationResult.buildSuccessResult("isThirdProcess",m.get("data"));
                }else{
                    return OperationResult.buildFailureResult(m.get("message")+"", m.get("data"));
                }

            }
        } catch (JsonProcessingException e) {
            LOG.error("启动流程失败", e);
            return OperationResult.buildFailureResult("启动流程失败");
        }

        if(StringUtils.isBlank(openUrl)){
            return  OperationResult.buildFailureResult("启动流程失败，请联系管理员");
        }else{
            return OperationResult.buildSuccessResult(openUrl);
        }
    }

    @ApiOperation(value = "获取紧急程度数据", notes = "")
    @RequestMapping(value = "/getUrgencyLevelList", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getUrgencyLevelList() {
        WebUser user = WebUtils.getCurrentUser();
        List allList = new ArrayList();
        HashMap<String, Object> mapData = new HashMap<>();
        List<Map<String, Object>> urgencyLevel = pendingTaskService.getUrgencyLevelList("urgencyLevel", user.getCorpId(), user.getJwtToken());
        boolean isDefault=false;
        Map<String, Object> map0=new HashMap<>();
        for( Map<String, Object> map1 : urgencyLevel){
            String code = map1.get("code").toString();
            String name = map1.get("name").toString();
            Map map2 = new HashMap();
            map2.put("id",code);
            map2.put("text",name);
            allList.add(map2);
            if(StringUtils.equals("0",code)){
                map0=map2;
            }
            if(StringUtils.null2String(map1.get("isDefault")).equals("1")){
                mapData.put("deault",map2);
                isDefault=true;
            }
        }
        if(!isDefault){
            mapData.put("deault",map0);
        }
        mapData.put("urgencyFieldList",allList);
        return OperationResult.buildSuccessResult(mapData);
    }

    @ApiOperation(value = "根据id获取函数信息", notes = "")
    @RequestMapping(value = "/getFunctionInfoById", method = RequestMethod.GET)
    @ResponseBody
    public OperationResult getFunctionInfoById(String functionId) {
        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("functionId",functionId);
        String json = approveApiClient.getFunctionInfoById(paramMap, user.getJwtToken());
        Map dataMap = new HashMap();
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                if(map.get("data") instanceof Map){
                    dataMap = (Map)map.get("data");
                }
            }
            return OperationResult.buildSuccessResult(dataMap);
        }
        return OperationResult.buildFailureResult("根据id获取函数信息失败");
    }


    @ApiOperation(value = "合并保存任务", notes = "合并保存任务")
    @RequestMapping(value = "/mergeSaveTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult mergeSaveTask(HttpServletRequest request) {
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String> bodyParams = new HashMap<String, String>();
        WebUser user = WebUtils.getCurrentUser();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        bodyParams.put("taskDefKey",request.getParameter("taskDefKey"));
        bodyParams.put("taskInfoList",request.getParameter("taskInfoList"));
        String json = approveApiClient.mergeSaveTask( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "合并提交任务", notes = "合并提交任务")
    @RequestMapping(value = "/mergeCompleteTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult mergeCompleteTask(HttpServletRequest request) {
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String> bodyParams = new HashMap<String, String>();
        WebUser user = WebUtils.getCurrentUser();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        bodyParams.put("taskDefKey",request.getParameter("taskDefKey"));
        String taskInfoList = request.getParameter("taskInfoList");
        bodyParams.put("taskInfoList",taskInfoList);
        bodyParams.put("msgType",request.getParameter("msgType"));
        String selectedActivity = request.getParameter("selectedActivity");
        if(StringUtils.isNotBlank(selectedActivity)){
            bodyParams.put("selectedActivity",selectedActivity);
        }
        bodyParams.put("dealActionName",request.getParameter("dealActionName"));
        String activityNodeNow = request.getParameter("activityNodeNow");
        bodyParams.put("activityNodeNow",request.getParameter("activityNodeNow"));
        String json = approveApiClient.mergeCompleteTask( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(json);
        if ("success".equals(map.get("type").toString())) {
            String module = request.getParameter("module");
            List<Map> list = JsonUtils.readListValue(taskInfoList);
            for(Map map1 : list) {
                String taskId = StringUtils.null2String(map1.get("taskId"));
                String processInstanceId = StringUtils.null2String(map1.get("processInstanceId"));
                Map ms = new HashMap();
                ms.put("taskId",taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
            }
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "合并退回任务", notes = "合并退回任务")
    @RequestMapping(value = "/mergeBackTask", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult mergeBackTask(HttpServletRequest request) {
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String> bodyParams = new HashMap<String, String>();
        WebUser user = WebUtils.getCurrentUser();
        params.put("userId", user.getUserId());
        params.put("corpId", user.getCorpId());
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        bodyParams.put("taskDefKey",request.getParameter("taskDefKey"));
        String taskInfoList = request.getParameter("taskInfoList");
        bodyParams.put("taskInfoList",taskInfoList);
        bodyParams.put("msgType",request.getParameter("reminders"));
        bodyParams.put("selectedActivity",request.getParameter("selectedActivity"));
        bodyParams.put("dealActionName",request.getParameter("dealActionName"));
        bodyParams.put("targetId",request.getParameter("targetId"));
        bodyParams.put("targetUserId",request.getParameter("targetUserId"));
        bodyParams.put("targetName",request.getParameter("targetName"));
        bodyParams.put("targetUserName",request.getParameter("targetUserName"));
        bodyParams.put("backType",request.getParameter("backType"));
        String module = request.getParameter("module");
        String backReasonText = request.getParameter("backReasonText");
        String json = approveApiClient.mergeBackTask( params,JsonUtils.writeValueAsString(bodyParams),user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(json);
        if ("success".equals(map.get("type").toString())) {
            Map<String, Object> map1 = (Map<String, Object>) map.get("data");
            if(null!=map1 && map1.size()>0){
                List<Map> list = JsonUtils.readListValue(taskInfoList);
                for(Map map2 : list) {
                    String taskId = StringUtils.null2String(map2.get("taskId"));
                    String processInstanceId = StringUtils.null2String(map2.get("processInstanceId"));
                    List doingList = (List) map1.get(taskId);
                    doingList.remove(taskId);
                    Map<String, String> ms = new HashMap<String, String>();
                    ms.put("taskId", taskId);
                    pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
                    pendingTaskService.deleteMessages(user.getUserId(), user.getCorpId(), StringUtils.collectionToDelimitedString(doingList,","), user.getJwtToken(), module);
                    List<Map> doingList1 = pendingTaskService.getTaskAndUser(processInstanceId, request.getParameter("targetId"));
                    String taskIds="";
                    for(Map m:doingList1){
                        taskIds=taskIds+","+m.get("taskId");
                    }
                    pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), backReasonText,
                            "1", taskIds);
                }
            }
        }
        return pendingTaskService.stringToOperation(json);
    }

    @ApiOperation(value = "根据任务id意见征询操作", notes = "根据任务id意见征询操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "consultUserId", value = "被征询人id,多个逗号分隔", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "consultTime", value = "征询时间（转成分钟）", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "consultComment", value = "征询意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealactionname", value = "操作名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务ID", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/consultationComment", method = RequestMethod.POST, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult consultationComment(HttpServletRequest request) {
        //非法参数校验
       // ApproveValidateUtils.validateRequestParmas(request);
        WebUser user = WebUtils.getCurrentUser();
        String consultUserId = StringUtils.null2String(request.getParameter("consultUserId"));
        String consultTime = StringUtils.null2String(request.getParameter("consultTime"));
        String dealactionname = StringUtils.null2String(request.getParameter("dealactionname"));
        String consultComment = StringUtils.null2String(request.getParameter("consultComment"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        String module = StringUtils.null2String(request.getParameter("module"));
        String minutes = "";
        if(consultTime != ""){
            LocalTime time = LocalTime.parse(consultTime);
            minutes = time.getHour() * 60 + time.getMinute()+"";
        }
        HashMap<String, String> params = new HashMap<>();
        HashMap<String, Object> bodyParams = new HashMap<>();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        bodyParams.put("groupId",orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());
        bodyParams.put("clientType","0");//移动端办理标志为1
        bodyParams.put("dealactionname",dealactionname);//操作名称
        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        params.put("userId", user.getUserId());
        params.put("consultUserId", consultUserId);
        params.put("consultTime", minutes);
        params.put("consultComment", consultComment);
        params.put("taskId", taskId);
        String result = approveApiClient.consultationComment(params,bodyString,user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(result);
        if(!"success".equals(StringUtils.null2String(map.get("type")))){
            return OperationResult.buildFailureResult("意见征询操作失败");
        }
        Map<String, String> ms = new HashMap<String, String>();
        ms.put("taskId", taskId);
        pendingTaskService.takeMsgDoneSleep(module, processInstanceId,ms,user.getUserId(),user.getCorpId(),user.getJwtToken());
        Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
        String modiInfo = "";
        if (null != dataMap && null != dataMap.get("modiInfo")) {
            modiInfo = dataMap.get("modiInfo") + "";
        }
        if (StringUtils.isNotBlank(modiInfo)) {
            pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), modiInfo,
                    "0", pendingTaskService.getDoingTaskIds(processInstanceId));
        }
        /** 流程办理 释放签批锁 **/
        this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
        /** 清理办理人正文锁信息 **/
        bpmProcessTextlockService.delTextlock(user.getUserId(),processInstanceId);
        return OperationResult.buildSuccessResult("意见征询操作成功");
    }


    @ApiOperation(value = "根据任务id获取征询意见和转交意见", notes = "根据任务id获取征询意见和转交意见")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务ID", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/getConsultComList", method = RequestMethod.GET, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult getConsultComList(HttpServletRequest request){
        //非法参数校验
       // ApproveValidateUtils.validateRequestParmas(request);
        WebUser user = WebUtils.getCurrentUser();
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        HashMap<String, String> params = new HashMap<>();
        params.put("userId", user.getUserId());
        params.put("taskId", taskId);
        String jsonResult = approveApiClient.getConsultComList(params,user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(jsonResult);
        if(!"success".equals(StringUtils.null2String(map.get("type")))){
            return OperationResult.buildFailureResult("根据任务id获取征询意见和转交意见失败");
        }
        return OperationResult.buildSuccessResult("成功", map.get("data"));
    }

    @ApiOperation(value = "根据任务id征询转交操作", notes = "根据任务id征询转交操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transferUserId", value = "征询转交人id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "transferComment", value = "征询意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealactionname", value = "操作名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务ID", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/consultationTransfer", method = RequestMethod.POST, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult consultationTransfer(HttpServletRequest request) {
        //非法参数校验
       // ApproveValidateUtils.validateRequestParmas(request);
        WebUser user = WebUtils.getCurrentUser();
        String transferUserId = StringUtils.null2String(request.getParameter("transferUserId"));
        String transferComment = StringUtils.null2String(request.getParameter("transferComment"));
        String dealactionname = StringUtils.null2String(request.getParameter("dealactionname"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String module = StringUtils.null2String(request.getParameter("module"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        HashMap<String, String> params = new HashMap<>();
        params.put("userId", user.getUserId());
        params.put("transferUserId", transferUserId);
        params.put("transferComment", transferComment);
        params.put("taskId", taskId);
        HashMap<String, Object> bodyParams = new HashMap<>();
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        bodyParams.put("groupId",orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());
        bodyParams.put("clientType","0");//移动端办理标志为1
        bodyParams.put("dealactionname",dealactionname);//操作名称
        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        String jsonResult = approveApiClient.consultationTransfer(params,bodyString,user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(jsonResult);
        if(!"success".equals(StringUtils.null2String(map.get("type")))){
            return OperationResult.buildFailureResult(StringUtils.null2String(map.get("message")));
        }
        Map<String, String> ms = new HashMap<String, String>();
        ms.put("taskId", taskId);
        pendingTaskService.takeMsgDoneSleep(module,processInstanceId,ms,user.getUserId(),user.getCorpId(),user.getJwtToken());

        Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
        String modiInfo = "";
        if (null != dataMap && null != dataMap.get("modiInfo")) {
            modiInfo = dataMap.get("modiInfo") + "";
        }
        if (StringUtils.isNotBlank(modiInfo)) {
            pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), modiInfo,
                    "0", pendingTaskService.getDoingTaskIds(processInstanceId));
        }
        /** 流程办理 释放签批锁 **/
        this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);
        /** 清理办理人正文锁信息 **/
        bpmProcessTextlockService.delTextlock(user.getUserId(),processInstanceId);
        return OperationResult.buildSuccessResult("根据任务id征询转交操作成功");
    }

    @ApiOperation(value = "根据任务id征询回复操作", notes = "根据任务id征询回复操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "replyComment", value = "回复意见", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealactionname", value = "操作名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务ID", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/consultationReply", method = RequestMethod.POST, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult consultationReply(HttpServletRequest request) {
        //非法参数校验
       // ApproveValidateUtils.validateRequestParmas(request);
        WebUser user = WebUtils.getCurrentUser();
        String replyComment = StringUtils.null2String(request.getParameter("replyComment"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String dealactionname = StringUtils.null2String(request.getParameter("dealactionname"));
        String module = StringUtils.null2String(request.getParameter("module"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        HashMap<String, String> params = new HashMap<>();
        HashMap<String, Object> bodyParams = new HashMap<>();
        params.put("userId",user.getUserId());
        params.put("replyComment",replyComment);
        params.put("taskId",taskId);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        bodyParams.put("groupId",orgId);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());
        bodyParams.put("clientType","0");//移动端办理标志为1
        bodyParams.put("dealactionname",dealactionname);//操作名称
        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        String jsonResult = approveApiClient.consultationReply(params,bodyString,user.getJwtToken());
        Map<String, Object> map = JsonUtils.readValue(jsonResult);
        if(!"success".equals(StringUtils.null2String(map.get("type")))){
            return OperationResult.buildFailureResult(StringUtils.null2String(map.get("message")));
        }
        Map<String, String> ms = new HashMap<String, String>();
        ms.put("taskId", taskId);
        pendingTaskService.takeMsgDoneSleep(module, processInstanceId ,ms,user.getUserId(),user.getCorpId(),user.getJwtToken());
        Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
        String modiInfo = "";
        if (null != dataMap && null != dataMap.get("modiInfo")) {
            modiInfo = dataMap.get("modiInfo") + "";
        }
        if (StringUtils.isNotBlank(modiInfo)) {
            pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), modiInfo,
                    "0", pendingTaskService.getDoingTaskIds(processInstanceId));
        }

        /** 流程办理 释放签批锁 **/
        this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);

        /** 清理办理人正文锁信息 **/
        bpmProcessTextlockService.delTextlock(user.getUserId(),processInstanceId);
        return OperationResult.buildSuccessResult("根据任务id征询回复操作成功");
    }

    @ApiOperation(value = "领导退回操作", notes = "领导退回操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "backReasonText", value = "退回原因", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "commentInfoList", value = "批示意见列表", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "module", value = "模块编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "msgType", value = "提醒方式", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "permissionCode", value = "权限编码", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processTitle", value = "流程标题", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dealActionName", value = "操作名称", required = false, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/leaderBack", method = RequestMethod.POST, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult leaderBack(HttpServletRequest request) {
        LOG.debug("开始  领导退回秘书   leaderBack:");
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        //---------- 平行越权  2022年6月15日18:52:50
        String secdatacode = StringUtils.null2String(request.getParameter("secdatacode"));
        if(!ApproveSecUtils.verifyData("processInstanceId"+processInstanceId,secdatacode)){
            return OperationResult.buildFailureResult(ApproveConstants.NO_RIGHT_OPT_MSG);
        }
        //---------- 平行越权  2022年6月15日18:52:50
        String commentInfoList = StringUtils.null2String(request.getParameter("commentInfoList"));
        String backReasonText = StringUtils.null2String(request.getParameter("backReasonText"));
        String msgType = StringUtils.null2String(request.getParameter("msgType"));
        String dealActionName = StringUtils.null2String(request.getParameter("dealActionName"));
        String module = StringUtils.null2String(request.getParameter("module"));
        String permissionCode = StringUtils.null2String(request.getParameter("permissionCode"));
        String processTitle = StringUtils.null2String(request.getParameter("processTitle"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String nowActivityId = StringUtils.null2String(request.getParameter("nowActivityId"));

        WebUser user = WebUtils.getCurrentUser();
        Map<String, String> params = new HashMap<String, String>();
        String userId = user.getUserId();
        params.put("userId", userId);
        params.put("corpId", user.getCorpId());
        params.put("taskId", taskId);
        String orgId = user.getCurrentPtOrgId();
        if (StringUtils.isBlank(orgId)) {
            orgId = user.getOrgId();
        }
        params.put("groupId", orgId);
        Map<String, Object> bodyParams = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(msgType) && !"null".equals(msgType) && !"undefined".equals(msgType)) {
            bodyParams.put("msgType", msgType);
        }
        if (StringUtils.isNotBlank(commentInfoList)) {
            bodyParams.put("commentInfoList", commentInfoList);
        }
        bodyParams.put("backReasonText", backReasonText);//退回原因
        bodyParams.put("dealActionName", dealActionName);
        bodyParams.put("stationId",user.getCurrentPtStationId());//当前切换的岗位id
        bodyParams.put("dutyId",user.getCurrentPtDutyId());//当前切换的职务id
        bodyParams.put("clientType","0");//移动端办理标志为1
        String bodyString = JsonUtils.writeValueAsString(bodyParams);
        permissionCode = module + ":" + permissionCode + ":bh";
        String json = approveApiClient.leaderBack(params,bodyString,user.getJwtToken());
        LOG.debug("back   json:"+json);
        try {
            Map<String, Object> map = JsonUtils.readValue(json);
            if ("success".equals(map.get("type").toString())) {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, processTitle, null);
                }
                Map<String, String> ms = new HashMap<String, String>();
                ms.put("taskId", taskId);
                pendingTaskService.takeMsgDoneSleep(module, processInstanceId, ms, user.getUserId(), user.getCorpId(), user.getJwtToken());
                List<Map> doingList = pendingTaskService.getTaskAndUser(processInstanceId, nowActivityId);
                String taskIds="";
                for(Map m:doingList){
                    taskIds=taskIds+","+m.get("taskId");
                }
                pendingTaskService.updateProcessLog(processInstanceId, taskId, user.getCorpId(), backReasonText,
                        "1", taskIds);

                /** 清理办理人信息的缓存 **/
                this.pendingTaskService.delApproveDealUserCache("[{\"id\":\""+taskId+"\"}]",taskId);

                /** 流程办理 释放签批锁 **/
                this.bpmProcessFormofdService.dealDealUserInfo(processInstanceId);

                /** 清理办理人正文锁信息 **/
                this.bpmProcessTextlockService.delTextlock(userId,processInstanceId);

            } else {
                if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                    logService.saveModuleLog(permissionCode, processTitle, null, UuidUtils.UUID());
                }
            }
        } catch (Exception e) {
            if (logService.checkOptLog(user.getCorpId(), permissionCode, user.getJwtToken())) {
                logService.saveModuleLog(permissionCode, processTitle, null, UuidUtils.UUID());
            }
            LOG.error("领导退回秘书", e);
            return OperationResult.buildFailureResult("领导退回秘书");
        }
        if(StringUtils.isNotBlank(json)){
            Map map=JsonUtils.readValue(json);
            if(StringUtils.equals("success", map.get("type")+"")){
                return OperationResult.buildSuccessResult(map.get("data"));
            }
            return OperationResult.buildFailureResult(map.get("message")+"", map.get("data"));
        }else{
            return OperationResult.buildFailureResult("参数不能为空");
        }
    }

    @ApiOperation(value = "获取存在的待办任务id", notes = "获取存在的待办任务id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskIds", value = "任务ID", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/getExistUndoTaskId", method = RequestMethod.GET, produces = {
            "application/json; charset=UTF-8"})
    public OperationResult getExistUndoTaskId(HttpServletRequest request){
        String taskIds = StringUtils.null2String(request.getParameter("taskIds"));
        return OperationResult.buildSuccessResult("成功", pendingTaskService.getExistUndoTaskId(taskIds));
    }


    @ApiOperation(value = "获取附件集合", notes = "")
    @RequestMapping(value = "/getAttachmentListForPc", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "数据id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单id", required = false, paramType = "query", dataType = "String")})
    @ResponseBody
    public OperationResult getAttachmentListForPc(HttpServletRequest request) {
        //非法参数校验
        ApproveValidateUtils.validateRequestParmas(request);
        String dataId = StringUtils.null2String(request.getParameter("dataId"));
        String formId = StringUtils.null2String(request.getParameter("formId"));
        String taskId = StringUtils.null2String(request.getParameter("taskId"));
        String processInstanceId = StringUtils.null2String(request.getParameter("processInstanceId"));
        List<Map<String, Object>> jsonList = approveTransformService.getAttachmentList(dataId,formId,taskId,processInstanceId);
        return OperationResult.buildSuccessResult(jsonList);
    }
    /**
     * 附件页签批量下载
     * @name: batchDownloadFiles
     * @param request
     * @param response
     * @param token 用户token

     * @return: void
     * @date: 2022/10/17 16:35
     *
     */
    @RequestMapping(value = "/batchDownloadFiles", method = RequestMethod.GET)
    public void batchDownloadFiles(HttpServletRequest request, HttpServletResponse response,String token) throws IOException {
        //附件id集
        List<String> fileIdList = new ArrayList<String>();
        String documentId = request.getParameter("documentId");
        String category = request.getParameter("category");
        String ids = request.getParameter("ids");
        String signFlag = request.getParameter("signFlag");
        String displayNameMap = StringUtils.null2String(request.getParameter("displayNameMap"));
        if(StringUtils.isEmpty(ids)||StringUtils.isEmpty(documentId)||StringUtils.isEmpty(category)) {
            LOG.error("参数错误!");
            return;
        }
        String[] idArr = ids.split("\\|");
        StringBuilder fileIdStr = new StringBuilder();
        if(idArr!=null&&idArr.length>0) {
            for(int i=0;i<idArr.length;i++) {
                if(StringUtils.isNotBlank(idArr[i])){
                    fileIdList.add(idArr[i]);
                    fileIdStr.append(",");
                    fileIdStr.append(idArr[i]);
                }
            }
        }
        String fileIdStrs = fileIdStr.toString();
        if(fileIdStr.length()>0){
            fileIdStrs = fileIdStrs.substring(1);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String title = "审批";
        Integer fileNum = 0;
        String  filenum = "";
        // 将多个文件打成压缩包下载
        ZipOutputStream zos = null;
        BufferedOutputStream bos = null;
        BufferedInputStream bis = null;
        try {
            List<Map<String, String>> attachmentList = null;
            attachmentList =  attachmentUtilsService.getAttachmentByIds(fileIdStrs,"0",token);
            int filesize = attachmentList.size();
            if(filesize<10) {
                filenum = "0"+filesize;
            }else {
                filenum = ""+filesize;
            }
            response.setContentType("application/x-msdownload");
            String newTitle = title+"_附件共"+filenum+ "个_"+sdf.format(new Date())+".zip";
            newTitle = AttachUtils.encodingFileName(newTitle, request);
            String headerDispositionDefault = "attachment";
            if (request.getHeader("User-Agent")!=null && request.getHeader("User-Agent").toLowerCase().indexOf("firefox") != -1) {
                response.addHeader("Content-Disposition", headerDispositionDefault+";filename*=UTF-8''" + newTitle);
            } else {
                response.setHeader("Content-Disposition", headerDispositionDefault+";filename=\"" + newTitle+"\"");
            }
            zos = new ZipOutputStream(response.getOutputStream());
            bos = new BufferedOutputStream(zos);
            if(attachmentList!=null&&attachmentList.size()>0) {
                for (int j = 0; j < attachmentList.size(); j++) {
                    Map<String, String> attachmentFile = attachmentList.get(j);
                    if(attachmentFile!=null) {
                        // 文件序号
                        fileNum++;
                        String attachId = attachmentFile.get("id");
                        String checksum = attachmentFile.get("checksum");
                        String fileDisplayName = attachmentFile.get("fileDisplayName");
                        if(StringUtils.isNotBlank(displayNameMap)){
                            Map<String, Object> map = JsonUtils.readValue(displayNameMap);
                            Set<Map.Entry<String, Object>> entries = map.entrySet();
                            for (Map.Entry<String, Object> entry : entries) {
                                if(entry.getKey().equals(attachId)){
                                    fileDisplayName = entry.getValue().toString();
                                    break;
                                }
                            }
                        }
                        String securityClassificat = attachmentFile.get("name");
                        String fileName = "";
                        String num = "";
                        if(fileNum<10) {
                            num = "0"+fileNum;
                        }else {
                            num = ""+fileNum;
                        }
                        if(StringUtils.isNotEmpty(securityClassificat)) {
                            fileName = num+" 【"+securityClassificat+"】" +fileDisplayName;
                        }else {
                            fileName = num+" "+fileDisplayName;
                        }
                        byte[] attachFile = attachmentUtilsService.download(attachId, checksum, token);
                        bis = new BufferedInputStream(new ByteArrayInputStream(attachFile));

                        ZipEntry zipEntry = new ZipEntry(fileName);
//                        zipEntry.setUnixMode(777);
                        zos.putNextEntry(zipEntry);
                        int len = 0;
                        byte[] buf = new byte[10 * 1024];
                        while ((len = bis.read(buf, 0, buf.length)) != -1) {
                            bos.write(buf, 0, len);
                        }
                        bos.flush();
                        bis.close();

                    }
                }
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }finally {
            zos.close();
            bos.close();
            bis.close();
        }

    }
}
